⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 soln7_5.cpp

📁 Wrox.Ivor.Hortons.Beginning.Visual.C.Plus.Plus.2008 With sourcecode
💻 CPP
字号:
// Soln7_5.cpp
/*
  When you create a CTRace object the constructor outputs a message.
  At the end of the block in which a CTrace object is created on the stack, the object
  will be destroyed automatically and the destructor called.
  The destructor outputs a message to indicate the end of the block.
  Of course a block can be a function or a nested block within a function.
*/

#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;
};

// Constructor
CTrace::CTrace(const char* str)
{
  size_t len = strlen(str)+1;
   pstr = new char[len];
   strcpy_s(pstr, len, str);
   cout << "Entry: " << pstr << endl;
}

// Destructor
CTrace::~CTrace()
{
   cout << "Exit: " << pstr << endl;
   delete pstr;
   pstr = 0;
}

int main()
{
   CTrace trace("Main routine");

   if (3 > 5)
   {
      CTrace trace1("'if' block");
   }
   else
   {
      CTrace trace2("'else' block");
   }

   return 0;
}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -