Hi,
I have this piece of code:
When I try to compile it, I get following error:Code:#include <iostream> using namespace std; class Float { public: Float() : Value(0.0f) {} Float(float NewValue) :Value(NewValue) {} ~Float() {} const Float operator+ (Float F) { return Float(F.Value+Value); } protected: float Value; }; class Vector2D { public: Vector2D() : X(0.0f), Y(0.0f){} Vector2D(Float NewX, Float NewY) : X(NewX), Y(NewY) {} ~Vector2D() {} Float X, Y; protected: }; class SomeThing { public: SomeThing() {} ~SomeThing() {} //if I take away 'const' in the beginning of next line, everything is ok const Vector2D getVector() const {return Vector;} protected: Vector2D Vector; }; int main() { SomeThing Thing; Float K=Thing.getVector().X + Thing.getVector().Y; }
What does that mean?main.cpp:49: error: passing `const Float' as `this' argument of `const Float
Float::operator+(Float)' discards qualifiers
But if I take away the const modifier before SomeThing::getVector() - as the comment in the code above indicates - everything compiles fine...
thanx :)



LinkBack URL
About LinkBacks


