J
Jacek Dziedzic
The said:I have created the following conversion in the header file
for my struct called SomeStruct.
operator std::string () {return "some useless text";}
I'm using it as follows.
SomeStruct someS;
std:cout << (std::string)someS;
This far, everything works just fine. Now, i got lazy of
constantly writing the string-part so i thought i'd like to
extend my struct to be convertible to a stream. So i
went as follows.
operator std:stream () {return "some other text";}
This didn't work, however. I don't understand the error
messages either. Any hints?
Also, would it be a smarter idea to overload << operator
for my struct?
Definitely.
How do i do that? I've played around
with friend-keyword but frankly, i must be missing
something, getting nowhere. Any help is appreciated...
You need a standalone function, not a member of a
class. Something like
ostream& operator<<(ostream& whither, const yourstruct& what) {
whither << "some useless text";
return whither;
}
HTH,
- J.