Hi,
I have this piece of code:
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;
}
When I try to compile it, I get following error:
main.cpp:49: error: passing `const Float' as `this' argument of `const Float
Float::operator+(Float)' discards qualifiers
What does that mean?
But if I take away the const modifier before SomeThing::getVector() - as the comment in the code above indicates - everything compiles fine...
thanx :)