我有一个类似基本堆栈的类。在我的成员函数定义中,我在vec的每个实例都会收到错误。该错误告诉我表达式必须具有类类型。我该怎么做才能解决这个问题?
class Stack{
public:
Stack();
Stack & push(double & t);
double pop() const;
unsigned long long getElements();
private:
vector <double> vec[10];
static double answer;
};
Stack::Stack(){
answer=0;
}
Stack & Stack::push(double & t){
vec.push_back(t);
return *this;
}
double Stack::pop()const{
return vec.pop_back();
}
unsigned long long Stack::getElements(){
return vec.size();
}
答案 0 :(得分:2)
这里有很多问题,修好后我得到了:
#include <vector>
using namespace std;
class Stack{
public:
Stack();
Stack & push(double & t);
double pop();
unsigned long long getElements();
private:
vector <double> vec;
static double answer;
};
Stack::Stack(){
answer=0;
}
Stack & Stack::push(double & t){
vec.push_back(t);
return *this;
}
double Stack::pop(){
double ret = vec.back();
vec.pop_back();
return ret;
}
unsigned long long Stack::getElements(){
return vec.size();
}
我所做的改变是: