[C++] Overloaded operators?

From: Bode, Wyatt (wjbode@BEMIS.COM)
Date: 09/03/97


Real quick question...

How the heck do you overload the '<<' operator in C++ to be used by
cout?  I tried the following:

unsigned char * String::operator << (String instr) {
        return (value);
}

The compiler sorta likes this, but later when I try to use it it pukes
(BTW, I'm using MSVC 5.0):

Compiling...
structs.cpp
D:\Program Files\In Progress\Test\structs.cpp(107) : error C2679: binary
'<<' : no operator defined which takes a right-hand operand of type
'class String' (or there is no acceptable conversion)
D:\Program Files\In Progress\Test\structs.cpp(112) : error C2679: binary
'<<' : no operator defined which takes a right-hand operand of type
'class String' (or there is no acceptable conversion)
D:\Program Files\In Progress\Test\structs.cpp(117) : error C2679: binary
'<<' : no operator defined which takes a right-hand operand of type
'class String' (or there is no acceptable conversion)
D:\Program Files\In Progress\Test\structs.cpp(122) : error C2679: binary
'<<' : no operator defined which takes a right-hand operand of type
'class String' (or there is no acceptable conversion)
D:\Program Files\In Progress\Test\structs.cpp(127) : error C2679: binary
'<<' : no operator defined which takes a right-hand operand of type
'class String' (or there is no acceptable conversion)
D:\Program Files\In Progress\Test\structs.cpp(132) : error C2679: binary
'<<' : no operator defined which takes a right-hand operand of type
'class String' (or there is no acceptable conversion)
Error executing cl.exe.

structs.obj - 6 error(s), 0 warning(s)

What am I doing wrong???
        -- Wyatt Bode


     +------------------------------------------------------------+
     | Ensure that you have read the CircleMUD Mailing List FAQ:  |
     | http://democracy.queensu.ca/~fletcher/Circle/list-faq.html |
     +------------------------------------------------------------+



This archive was generated by hypermail 2b30 : 12/08/00 PST