Stilllegung des Forums
Das Forum wurde am 05.06.2023 nach über 20 Jahren stillgelegt (weitere Informationen und ein kleiner Rückblick).
Registrierungen, Anmeldungen und Postings sind nicht mehr möglich. Öffentliche Inhalte sind weiterhin zugänglich.
Das Team von spieleprogrammierer.de bedankt sich bei der Community für die vielen schönen Jahre.
Wenn du eine deutschsprachige Spieleentwickler-Community suchst, schau doch mal im Discord und auf ZFX vorbei!
Werbeanzeige
Zitat
Deine erste Version war von der Funktionalität her schon richtig. Der Zuweisungsoperator soll ja etwas zuweisen. Wenn du einfach dein Objekt durchreichts hast du zum einen keine Kopie erzeugt, zum anderen gibst du ein nicht erwartetes Objekt zurück.
Zitat
d:\projects\main.cpp(60) : error C2801: 'operator =' must be a <Unknown> member
d:\projects\main.cpp\main.cpp(61) : error C2065: 'x' : undeclared identifier
d:\projects\main.cpp\main.cpp(61) : warning C4244: '=' : conversion from 'const float' to 'int', possible loss of data
d:\projects\main.cpp\main.cpp(62) : error C2065: 'y' : undeclared identifier
d:\projects\main.cpp\main.cpp(62) : warning C4244: '=' : conversion from 'const float' to 'int', possible loss of data
d:\projects\main.cpp\main.cpp(63) : error C2065: 'z' : undeclared identifier
d:\projects\main.cpp\main.cpp(63) : warning C4244: '=' : conversion from 'const float' to 'int', possible loss of data
d:\projects\main.cpp\main.cpp(64) : error C2673: '=' : global functions do not have 'this' pointers
d:\projects\main.cpp\main.cpp(69) : error C2805: binary 'operator +=' has too few parameters
d:\projects\main.cpp\main.cpp(70) : warning C4244: '+=' : conversion from 'const float' to 'int', possible loss of data
d:\projects\main.cpp\main.cpp(71) : warning C4244: '+=' : conversion from 'const float' to 'int', possible loss of data
d:\projects\main.cpp\main.cpp(72) : warning C4244: '+=' : conversion from 'const float' to 'int', possible loss of data
d:\projects\main.cpp\main.cpp(73) : error C2673: '+=' : global functions do not have 'this' pointers
Zitat von »"Melechesh"«
Ou, da hab ich wohl vor lauter Code die Lösung nicht gesehen! Vielen Dank hat funktioniert!
Nur mal so ne Verständniss-Frage: Wieso wird der "="- und der "!="-Operator anders behandelt als "+","-" usw. ? Gibt es da dafür einen speziellen Grund?
C-/C++-Quelltext |
|
1 2 3 4 5 6 7 8 |
class tdeVector3f { public: float x,y,z; //... tdeVector3f& operator=( const tdeVector3f& a ); //<- tdeVector3f& operator+=( const tdeVector3f& a ); //<- }; |
C-/C++-Quelltext |
|
1 2 |
inline tdeVector3f operator + (const tdeVector3f& a, const tdeVector3f& b) { |
C-/C++-Quelltext |
|
1 |
inline tdeVector3f& tdeVector3f::operator = (const tdeVector3f& a) |
C-/C++-Quelltext |
|
1 2 3 4 5 6 7 8 9 10 |
class tdeVector3f { public: tdeVector3f operator+( const tdeVector3f& a ) const; } tdeVector3f tdeVector3f::operator+( const tdeVector3f& a ) const { return tdeVector3f( x+a.x, y+a.y, z+a.z ); } |
Zitat von »"David_pb"«
Eine Ausnahme ist der operator=. Dieser sollte immer als Methode der jeweiligen Klasse deklariert sein.
Werbeanzeige