cannot access private member deklariert in der Klasse
Ich hab Stück code, es ist Methode definition
Move add(const Move & m) {
Move temp;
temp.x+= (m.x +this-x);
temp.y+= (m.y + this->y);
return temp;
}
und das ist Klasse Erklärung
class Move
{
private:
double x;
double y;
public:
Move(double a=0,double b=0);
void showMove() const;
Move add(const Move & m) const;
void reset(double a=0,double b=0);
};
Er sagt, dass
1>c:\users\filip\dysk google\c++\consoleapplication9\move.cpp(18): error C2248: 'Move::x' : cannot access private member declared in class 'Move'
1> c:\users\filip\dysk google\c++\consoleapplication9\move.h(7) : see declaration of 'Move::x'
1> c:\users\filip\dysk google\c++\consoleapplication9\move.h(5) : see declaration of 'Move'
1> c:\users\filip\dysk google\c++\consoleapplication9\move.h(7) : see declaration of 'Move::x'
1> c:\users\filip\dysk google\c++\consoleapplication9\move.h(5) : see declaration of 'Move'
1>c:\users\filip\dysk google\c++\consoleapplication9\move.cpp(18): error C2355: 'this' : can only be referenced inside non-static member functions
1>c:\users\filip\dysk google\c++\consoleapplication9\move.cpp(18): error C2227: left of '->x' must point to class/struct/union/generic type
und dasselbe gilt für Move::y . Any1 hat die Idee was ist das?
Du musst angemeldet sein, um einen Kommentar abzugeben.
Müssen Sie definieren
add
imMove
Klasse Umfang:Sonst wird interpretiert als eine nicht-member-Funktion, die keinen Zugang zu
Move
's nicht öffentlichen Mitglieder.Beachten Sie, dass Sie können den code vereinfachen, vorausgesetzt, die beiden parameter-Konstruktor setzt
x
undy
:const
zu zeigen =P)