last day (14 days later) » 

11:11 AM
1
A: Overloading operator<< Cannot bind basic_ostream<char> lvalue

Paolo MThe problem lies where you are invoking the operator<<, not in its definition. You are probably calling it in a context like this: std::ofstream() << "Hello World"; i.e. you are writing into a temporary ostream. That is in contrast with the definition of operator<<, in which you state that yo...

 
It's merely an implementation I haven't invoked it yet.
Is it possible that the error happened because of the lack of main()?
 
@J.Alvaro.T It sounds strange to me... I'm pretty sure you are calling it somewhere. Can you post a more comprehensive error message, so we can see where the error is?
@J.Alvaro.T Well, adding the main function sounds like a good idea, but I don't think the error was caused by that
@J.Alvaro.T Another (remote) possibility is that the error is inside d.month()...
 
I added the rest of the error message
 
Ok. Maybe the problem is that you have not defined the operator << for the type Month
 
I have to define operator<< for type Month when it's enum class?
 
11:13 AM
So, the compiler does not know what to do when you tell him: print out d.month()
Yes, you have
 
Hmm I'll try to define it then
 
Because Month() won't implicitly convert to some integer type, because it's declared as a enum CLASS
 
std::ostream& operator<<(std::ostream& os, Month& m)
{
    switch(m)
    {
    default:
        return os << "January";
    }
}
 
ok
 
It's only a basic operator<< overload for testing
But it still doesn't work
 
11:16 AM
You may want to take a const Mont& as an argument
What error do you get?
 
Ah yes
const Month& makes it work
thank you
 
yeah
 
Would you like to add the answer so I can accept it?
 
ok
ok ,we are done
goodbye ;)
 
bye :) thx
 
11:22 AM
Sorry, I've edited the answer again
By Month is a "small" type, you may want to pass it by value and not by ref
It's often convenient in terms of performance
 
Alright
thanks for the advice
 

last day (14 days later) »