Jump to content
  • Advertisement
Sign in to follow this  

Static std::ostream objects

This topic is 2827 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

I have a debug utility class that I use instead of cout. I do this because I want to be able to quickly switch between outputting to console, files, network, GUI, etc. All I would have to do would be set the ostream object up so that it's streambuff points to either a file, or cout. I already figured out how to attach a stream to cout. The problem is, I get undefined reference errors in Visual C++ when I try to declare a static ostream object. This is my class declaration:

///@brief The DebugUtils class contains debugging functions for outputting strings to the console, or files.
class DebugUtils
///@brief This stream can be used instead of std::cout.
static std::ostream out;
///@brief The BaseGameApp class is a friend so that it can acces this class's constructor.
friend class BaseGameApp;
///@brief The DebugUtils constructor is only called by the game application.

How do I prevent undefined references to the DebugUtils::out? I have the constructor of that class being called by the main game app's constructor, so the debugging utilities can be used after creating an app. That's where I connect it to std::cout.

Share this post

Link to post
Share on other sites
The part inside the class definition is just a declaration. You need to provide a definition in addition to the declaration. In this case it would look like:

std::ostream DebugUtils::out;

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.

GameDev.net is your game development community. Create an account for your GameDev Portfolio and participate in the largest developer community in the games industry.

Sign me up!