再看面试宝典

it2024-07-26  68

     下面的代码是面试宝典第9章,面试例题2,95页的内容,但是我运行时并没有出现书中所说的错误,记录在此。

View Code 1 #include "stdafx.h" 2 #include <iostream> 3 #include <vector> 4 using namespace std; 5 6 class CDemo{ 7 public: 8 CDemo():str(NULL){}; 9 ~CDemo()10 {11 if(str){ 12 static int i=0;13 cout<<"&CDemo"<<i++<<"="<<(int *)this<<",str'="<<(int *)str<<endl;14 delete[] str;15 }16 };17 char* str;18 };19 20 int _tmain(int argc, _TCHAR* argv[])21 {22 CDemo dl;23 dl.str=new char[32];24 strcpy(dl.str,"hello world");25 vector<CDemo> *al=new vector<CDemo>();26 al->push_back(dl);27 28 delete al;29 delete dl;30 getchar();31 getchar();32 return 0;33 }

转载于:https://www.cnblogs.com/liuliunumberone/archive/2011/07/29/2113775.html

相关资源:Java面试宝典2019完整版
最新回复(0)