C++ Typedef向量给了我错误
我目前正在尝试从ShapeTwoD类中的驱动程序类访问向量 这是驱动程序类的头文件:C++ Typedef向量给了我错误,c++,vector,typedef,C++,Vector,Typedef,我目前正在尝试从ShapeTwoD类中的驱动程序类访问向量 这是驱动程序类的头文件: class Driver { private: public: //ShapeTwoD* sd; typedef vector<ShapeTwoD*> shapes; Driver(); friend class ShapeTwoD; void inputStatisticalData(); void computeArea(); }; if (shape == "square") {
class Driver {
private:
public:
//ShapeTwoD* sd;
typedef vector<ShapeTwoD*> shapes;
Driver();
friend class ShapeTwoD;
void inputStatisticalData();
void computeArea();
};
if (shape == "square") {
for(int i = 0; i < 4; i++) {
cout << "Please enter x-coordinate of pt." << i+1 << " : ";
cin >> point.x;
cout << "Please enter y-coordinate of pt." << i+1 << " : ";
cin >> point.y;
vertices.push_back(point);
}
sq->setName(shape);
sq->setContainsWarpSpace(type);
sq->setVertices(vertices);
shapes.push_back(sd); //this is the line that gives the error
}
类驱动程序{
私人:
公众:
//ShapeTwoD*sd;
类型定义向量形状;
驱动器();
朋友级形状树;
无效inputStatisticalData();
无效计算区域();
};
这是ShapeWod类的头文件:
class ShapeTwoD {
private:
string name;
bool containsWarpSpace;
vector<Vertices> vertices;
double area;
public:
ShapeTwoD();
ShapeTwoD(string,bool,vector<Vertices>,double);
ShapeTwoD* sd;
typedef vector<ShapeTwoD*> shapes;
...//other methods
};
类ShapeTwoD{
私人:
字符串名;
布尔空间;
向量顶点;
双区;
公众:
ShapeTwoD();
ShapeTwoD(字符串、布尔、向量、双精度);
ShapeTwoD*sd;
类型定义向量形状;
…//其他方法
};
这是驱动程序类中错误产生的方法:
class Driver {
private:
public:
//ShapeTwoD* sd;
typedef vector<ShapeTwoD*> shapes;
Driver();
friend class ShapeTwoD;
void inputStatisticalData();
void computeArea();
};
if (shape == "square") {
for(int i = 0; i < 4; i++) {
cout << "Please enter x-coordinate of pt." << i+1 << " : ";
cin >> point.x;
cout << "Please enter y-coordinate of pt." << i+1 << " : ";
cin >> point.y;
vertices.push_back(point);
}
sq->setName(shape);
sq->setContainsWarpSpace(type);
sq->setVertices(vertices);
shapes.push_back(sd); //this is the line that gives the error
}
if(形状==“正方形”){
对于(int i=0;i<4;i++){
cout SETCONTAINSWARSPACE(类型);
sq->设置顶点(顶点);
shapes.push_back(sd);//这是给出错误的行
}
这是我访问向量进行计算的方法:
double ShapeTwoD::computeArea() {
for (vector<ShapeTwoD*>::iterator itr = shapes.begin(); itr != shapes.end(); ++itr) {
if((*itr)->getArea() <= 1) {
(*itr)->setArea((*itr)->computeArea());
cout << "Area : " << (*itr)->getArea() << endl;
}
}
cout << "Computation complete! (" << shapes.size() << " records were updated!" << endl;
}
double ShapeWod::computeArea(){
对于(向量::迭代器itr=shapes.begin();itr!=shapes.end();++itr){
if((*itr)->getArea()setArea((*itr)->computeArea());
cout类型名称形状是在类驱动程序中定义的。因此,在类之外,您必须编写限定名称驱动程序::形状。
此外,形状不是对象。您可能无法编写例如shapes.size()。类型名称形状是在类驱动程序中定义的。因此,在类之外,您必须编写限定名称Driver::shapes。
此外,形状不是对象。您可能无法编写例如shapes.size()。类型名称形状是在类驱动程序中定义的。因此,在类之外,您必须编写限定名称Driver::shapes。
此外,形状不是对象。您可能无法编写例如shapes.size()。类型名称形状是在类驱动程序中定义的。因此,在类之外,您必须编写限定名称Driver::shapes。
此外,形状不是对象。您不能编写例如shapes.size()。typedef向量形状;
形状。推回(sd);
第一行表示shapes
是类型的名称。第二行(发生错误的地方)尝试使用shapes
作为对象的名称。typedef vector shapes;
形状。推回(sd);
第一行表示shapes
是类型的名称。第二行(发生错误的地方)尝试使用shapes
作为对象的名称。typedef vector shapes;
形状。推回(sd);
第一行表示shapes
是类型的名称。第二行(发生错误的地方)尝试使用shapes
作为对象的名称。typedef vector shapes;
形状。推回(sd);
第一行表示shapes
是类型的名称。第二行(发生错误的地方)尝试使用形状
作为对象的名称。形状
在两个类中声明。形状
在两个类中声明。形状
在两个类中声明。形状
在两个类中声明。您需要一个对象,可能是形状
类型。您所拥有的就像说的一样>int++
而不是int i;i++;
。所以我创建了一个像这样的对象typedef向量形状s;
?我的ShapeTwoD类中有什么abt?同样的事情?如果我问了太多问题。这个typedef
是一个新概念,我已经编辑了我的问题。你能看看我是否在使用typedef
吗>正确吗?你需要一个对象,大概是shapes
类型。你所说的是int++
而不是inti;i++;
。所以我创建了一个像这样的对象typedef向量形状;
?我的shapewod类中有什么?同样的事情?如果我问的问题太多,请回答。这个typedef
是一个新的c如果我要编辑我的问题,你能看看我是否正确使用了typedef
吗?你需要一个对象,大概是shapes
类型。你所说的是int++
而不是inti;I++;
。所以我创建了一个像typedef向量形状s;
?里面有什么我的ShapeWod类?同样的事情?如果我问的问题太多,请回答。这个typedef
对我来说是一个新概念。编辑我的问题,你能看看我是否正确使用typedef
吗?你需要一个对象,大概是shapes
类型。你所说的是int++
,而不是int i;i++;
。所以我创建了一个像这样的对象typedef vector shapes;
?我的ShapeTwoD类中有什么东西?同样的事情?如果我问的问题太多的话。这个typedef
对我来说是一个新概念。编辑我的问题,你能看看我是否正确使用了typedef
?
typedef vector<ShapeTwoD*> shapes;
shapes.push_back(sd);