I have a trouble with overloading operator<< for const objects.I couldnt find out the problem
#include <iostream>
using namespace std;
class T
{
friend ostream& operator<<(ostream& os,T& t)
{
os << "Val : " << t.value << endl;
return os;
}
private:
int value;
public:
T(int v) { value=v; }
int getValue() const { return value; }
};
int main()
{
const T t(2);
cout << t;
return 0;
}
Compiler Message:
error C2679: binary '<<' : no operator found which takes a right-hand operand of type 'const T' (or there is no acceptable conversion)