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請將您的答案作爲答案發布,而不是更新問題本身。 –