我不知道如何在构造函数中初始化struct向量。任何人都可以给我指针? ^^在构造函数中初始化struct的向量
这是我的结构:
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: error: no match for ‘operator=’ in ‘((ShapeTwoD*)this)->ShapeTwoD::vertices = ""’ /usr/include/c++/4.4/bits/vector.tcc:156: note: candidates are: std::vector<_Tp, _Alloc>& std::vector<_Tp, _Alloc>::operator=(const std::vector<_Tp, _Alloc>&) [with _Tp = Point, _Alloc = std::allocator]
请阅读教科书。谢谢。 – Abyx
请测试您自己的代码,并询问是否发现实际问题 - 最后一个.cpp文件中的注释表明您还没有尝试过运行它。 – UnholySheep
您在构造函数中初始化事物的方式已中断。阅读你的书,它会解释为什么。 – Griwes