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);
}
};
Mein Problem ist, mit:Typen myObj und myObj * sind nicht kompatibel
boundaryPtAry[index++] = new boundaryPt(x,y);
Ich versuche, meine boundaryPt Objekte in meinem Array vom Typ boundaryPt zu speichern, aber da ich erklärt, dass Array als boundaryPt * es wird mir nicht erlauben, ein boundaryPt zu speichern.
Ist das ein einfaches Problem, einen Zeiger zu deaktivieren? Ich bin rostig mit C++.
Wie wäre es mit 'boundaryPtAry [index] .x = x; boundaryPtAry [index] .y = y; index ++; '? – songyuanyao
Das hat funktioniert. Ich erkenne jetzt, dass wenn ich ein Array von Objekten erstelle, es tatsächlich die tatsächlichen Objekte erzeugt. Es ist also nicht notwendig, ein neues boundaryPt-Objekt zu erstellen. Vielen Dank! – user5904091
10 @ user5904091 Bitte posten Sie Ihre Antwort als Antwort, anstatt die Frage selbst zu aktualisieren. –