Jump to content
  • Advertisement
Sign in to follow this  
djwhy

Overloading

This topic is 4495 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

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 this post


Link to post
Share on other sites
Advertisement
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 this post


Link to post
Share on other sites
Quote:
Original post by djwhy
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.

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 this post


Link to post
Share on other sites
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 this post


Link to post
Share on other sites
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.

Share this post


Link to post
Share on other sites
Sign in to follow this  

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

We are the game development community.

Whether you are an indie, hobbyist, AAA developer, or just trying to learn, GameDev.net is the place for you to learn, share, and connect with the games industry. Learn more About Us or sign up!

Sign me up!