to fix your error:
B():debug(*(new std::ofstream("debug.txt"))){}
But: if you do so I guess you'll forget to delete...
So:
You better use a singleton to wrap the debug object
class Debug{
std::ofstream debug;
//private ctor, you can't create an object for this class outside
Debug(const std::string& filename):debug(filename){}
public:
//only way tou use this class is to call this method
static Debug* Instance(){
//the one and only Debug object, created at first use:
static Debug theObj("debug.txt");
return &theObj;
}
//write method
std::ostream& outstream(){
return debug;
}
};
//just for simplicity of use:
#define dbgout Debug::Instance()->outstream()
you can also define the macro like this:
#ifdef DEBUG
#define dbgout Debug::Instance()->outstream()
#else
// a release version won't create the debug file...
#define dbgout //
#endif
now you can use it like this from anywhere in your code:
dbgout<<" put your " << "stream " <<" here ";