views:

486

answers:

2

This function declaration gives me errors:

ostream& operator<<(ostream& os, hand& obj);

The errors are:

error C2143: syntax error : missing ';' before '&'
error C4430: missing type specifier
error C2065: 'os' : undeclared identifier
error C2065: 'obj' : undeclared identifier
error C2275: 'hand' : illegal use of this type as an expression
    see declaration of 'hand'
error C4430: missing type specifier

hand is a class I made, display is a public data member of type char*.

Can anybody tell me what I'm doing wrong?

+6  A: 

The declaration looks right. But the error message suggests that ostream is not known as a type. Try including the iostream header and say std::ostream instead.

Another thing you should consider is making the parameter 'hand' a const reference. So you could also accept temporaries and print them out.

Johannes Schaub - litb
+2  A: 

is this inside a header? then you probably need to say std::ostream. Make sure you #include<iosfwd>.

Also, you can probably say const hand&.

wilhelmtell