Long story short: i need to be able to define an operator with two different return types.
Something like this that actually works:
void operator>>(char * szBuffer);
bool operator>>(char * szBuffer);
44 D:\Dev-Cpp\..\tcp.h `bool TCPconnection_c::operator>>(char*)' and `void TCPconnection_c::operator>>(char*)' cannot be overloaded
Long story short: you can't do that. What is the use case you are attempting to solve? Chances are you are going about this the wrong way.
Originally Posted by like_no_other
I want to be able to call the operator in two ways:
1. not checking if it succeded:
2. checking a bool return to see if it worked:
Usefulness: rigurous error checking when needed, fast typing on tests/trivial uses - i'm writing some sort of stream object for a tcp connection.
if ( object>>pChar )
Both cases can be solved with the version that returns bool. In contexts where you don't care, you ignore it.
At any rate, this sort of overloading is impossible. The return type is not a part of the function signature.
C++ iostreams operators >> and << return a reference to the same stream to allow operator chaining. They also provide operator void* to make the stream object testable in boolean contexts (or you can google for "safe bool idiom" if you want to do better).