class boundaryPt{
public:
friend class KCurvature;
int x;
int y;
boundaryPt(int x, int y){
this->x = x;
this->y = y;
}
boundaryPt(){}
};
class KCurvature{
public:
boundaryPt* boundaryPtAry;
int numPts;
ifstream input;
KCurvature(char* inFile){
input.open(inFile);
input >> numPts;
boundaryPtAry = new boundaryPt[numPts];
}
void loadData(char* inFile){
input.open(inFile);
int x;
int y;
while(!input.eof()){
input >> x;
input >> y;
boundaryPtAry[index++] = new boundaryPt(x,y);
}
};
我的问题是:类型MyObj中和MyObj中*不兼容
boundaryPtAry[index++] = new boundaryPt(x,y);
我想保存在我喜欢的类型boundaryPt的阵列我boundaryPt对象,但自从我宣布数组boundaryPt *它不会让我存储一个边界点。
这是一个简单的问题,指出一个指针吗?我用C++生锈了。
'boundaryPtAry [index] .x = x; boundaryPtAry [index] .y = y;索引++;'? – songyuanyao
工作。我现在意识到,当我创建一个对象数组时,它实际上会创建实际的对象。所以它们甚至不需要创建一个新的boundaryPt对象。谢谢! – user5904091
@ user5904091请将您的答案作为答案发布,而不是更新问题本身。 –