## Recommended Posts

djwhy    122
Hi, I've got a simple 3d engie with a console and I want to write to it like I write to the system console. i.e. I want to do this console << "Some text"; How would I do this. I've had a go at overloading it as if I was overloading it to write to cout or any other ostream but reaplacing the ostream with my console class but I get strange errors when I compile it with gcc: console& console::operator<<(console&, const char*)’ must take exactly one argument What dose this mean? Am I on the right track? [Edited by - djwhy on March 25, 2006 7:08:26 PM]

##### Share on other sites
JohnBolton    1372
Define it as a non-member function like this:

console& operator<<(console&, const char*)

##### Share on other sites
robinei    187
Or remove the "console&" parameter from the member function.

##### Share on other sites
djwhy    122
Thanks for the sugestion. I've defined it as a non member function with only the 'const char*' argument but now it says it needs ecactly two arguments. Is this one of those unusual quirks in C++ that isn't very well documented and needs a really really specific solution.

##### Share on other sites
JohnBolton    1372
Quote:
 Original post by djwhyThanks for the sugestion. I've defined it as a non member function with only the 'const char*' argument but now it says it needs ecactly two arguments. Is this one of those unusual quirks in C++ that isn't very well documented and needs a really really specific solution.

Lets try again.
Quote:
 Define it as a non-member function like this:console& operator<<(console&, const char*)

Quote:
 Or remove the "console&" parameter from the member function.

In other words, choose one of the following:
    non-member function:     console& operator<<(console&, const char*)        member function:     console& operator<<(const char*)

##### Share on other sites
RDragon1    1205
Why not just inherit your class from std::streambuf? I think that's the preferred method of implementing a new 'stream target' (your engine's console). Then, you can just swap cout's streambuf with your own, and you can use cout to write to the engine console. Or you could inherit your own stream from std::ostream.

note: I could be a bit off - i've never actually tried to do this, but I think this was how it's 'accepted' to be done

##### Share on other sites
djwhy    122
Thanks dragon, don't think I was getting anywhere with the other way it just didn't work. I tought I would have to do something like that.