我不知道如何在构造函数中初始化结构向量。任何人都可以给我指点?^^
这是我的结构:
struct Point {
int x;
int y;
};
这是我的头文件:
class ShapeTwoD {
private:
string name;
bool containsWarpSpace;
vector<Point> vertices;
public:
ShapeTwoD();
ShapeTwoD(string,bool,vector<Point>);
virtual string getName();
virtual bool getContainsWarpSpace();
virtual string toString();
vector<Point> points;
virtual double computeArea() = 0;
virtual bool isPointInShape(int,int) = 0;
virtual bool isPointonShape(int,int) = 0;
virtual void setName(string);
virtual void setContainsWarpSpace(bool);
};
这是我的 .cpp 文件:
ShapeTwoD::ShapeTwoD() {
name = "";
containsWarpSpace = true;
vertices = "";
}
ShapeTwoD::ShapeTwoD(string name, bool containsWarpSpace,vector<Point>vertices) {
this->name = name;
this->containsWarpSpace = containsWarpSpace;
this->vertices = vertices;
}
它给了我这个错误:
ShapeTwoD.cpp:12: 错误: '((ShapeTwoD*)this)->ShapeTwoD::vertices = ""' /usr/include/c++/4.4/bits/vector.tcc:156 中的 'operator=' 不匹配: 注意:候选者是: std::vector<_Tp, _Alloc>& std::vector<_Tp, _Alloc>::operator=(const std::vector<_Tp, _Alloc>&) [with _Tp = Point, _Alloc =标准::分配器]