"pnsteiner@gmail.com" wrote:[color=blue]
>
> i want to use the << operator defined for ostream with an object that
> itself knows nothing of the operator, but is castable to ostream&. it
> seems that C++ doesn't do implicit casts before invoking a custom
> operator.
>[/color]
An operator is nothing else then an ordinary function with some strange syntax.
So when your compiler sees.
[color=blue]
> test t;
>
> t << "test\n"; // implicit cast doesn't compile[/color]
it transforms this into:
t.operator<<( "test\n" );
Then the compiler scans the class test, searching for a function operator<<.
Finding none, the compiler searches the freestanding functions for a standalone
.... operator<<( test&, const char* );
Finding none, the compiler gives up and emits an error message.
The problem with that is that the compiler doesn't try to cast an
object to something else, in order to be able to come up with a function
it can call. Either that object's class (or one of its base classes) has
that function or it has not.
--
Karl Heinz Buchegger
kbuchegg@gascad.at