a bug when developing extension module with boost.python

C

Chen Bin

1. We need a trace class CLog like:
....
CLog()<<"err msg"<<"anything you like"<<endl;
....

2. A programmer's design:
CLog:public ostringstream{
~CLog()
{
cout<<str().c_str()<<endl;
}
}


It crashes when python use this module. The key point is that in
CLog's destructor str().c_str() is kind of rubbish data.

3. Another programmer's design:
CLog:public ostringstream{
template<typename T>
ostream& operator<<(T &userdefined)
{
return _temp<<userdefined<<endl;
}

~CLog()
{
cout<<str().c_str()<<endl;
}

private:
ostringstream _temp;
}

This version works well.

3. My quesition
how could solution in .2 fail?

I have googled and got nothing helpful

BTW:
My development environment is

Win2000Pro
VC6 SP5
VC7.1
Python2.3(windows)
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Similar Threads


Members online

Forum statistics

Threads
473,755
Messages
2,569,536
Members
45,020
Latest member
GenesisGai

Latest Threads

Top