C
Chen Bin
1. We need a trace class CLog like:
....
CLog()<<"err msg"<<"anything you like"<<endl;
....
2. A programmer's design:
CLog
ublic 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
ublic 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)
....
CLog()<<"err msg"<<"anything you like"<<endl;
....
2. A programmer's design:
CLog
~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
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)