Debugging deeply nested structures

How do you do it?

So far, I have been using the following approach:

1
2
3
4
5
6
7
class Object
{public:
  void ComputeDebugString();// puts the debug strings of all its  
                            // members, as well as object specific information
                            // into the variable DebugString               
  std::string DebugString;
};


What is your style of doing this? (Just gathering good tips, thanks in advance!)
overload the operator<< for your class type so that you can convert it directly to a string like so:

std::stringstream theStream;
theStream << myObject;

This article could help a little but is an advanced concept. I don't know if there are similar articles on this site but you could certainly search the internet for other examples as well as the forums themselves for related threads.
http://www.codeguru.com/forum/showthread.php?t=401691

You've got the correct idea though. It is good to be thinking of creative ways of capturing the state of your objects so that they can be inserted into a stream.
Last edited on
Topic archived. No new replies allowed.