|
4鱼币
#include "stdafx.h"
#include <iostream> // For stream input/output
#include <cstring>
using std::cout;
using std::endl;
class CTrace
{
public:
CTrace(const char* str);
~CTrace();
private:
char* pstr;
};
CTrace::CTrace(const char* str)
{
size_t len = strlen(str)+1;
pstr = new char[len];
strcpy_s(pstr, len, str);
cout << "Entry: " << pstr << endl;
}
CTrace::~CTrace()
{
cout << "Exit: " << pstr << endl;
delete pstr;
pstr = NULL;
}
int main()
{
CTrace trace("Main routine");
if (3 > 5)
{
CTrace trace1("'if' block");
}
else
{
CTrace trace2("'else' block");
}
return 0;
}
为什么到最后会出现退出消息?
怎么做到的
|
|