针对http://wenku.baidu.com/view/56d732ee856a561252d36ff2.html的内容测试一下。
1 #include "A.h" 2 #include <iostream> 3 #include <string> 4 using namespace std; 5 int main() 6 { 7 A *aa=new A(); 8 printf("aa=%x ",&aa); 9 A *b=NULL; 10 cout<<"——开始循环:"<<endl; 11 for (int i=0;i<3;i++) 12 { 13 A *bb=new A(); 14 printf("物理地址:bb=%x ",&bb); 15 delete bb; 16 17 A cc; 18 printf("物理地址:cc=%x ",&cc); 19 20 } 21 cout<<"——循环结束。"<<endl; 22 delete aa; 23 string str; 24 cin>>str; 25 return 1; 26 27 }
类A的头文件和实现:
1 #pragma once 2 class A 3 { 4 public: 5 A(void); 6 ~A(void); 7 };
1 #include "A.h" 2 #include <iostream> 3 using namespace std; 4 A::A(void) 5 { 6 cout<<"我是A的构造函数,呵呵呵"<<endl; 7 } 8 9 10 A::~A(void) 11 { 12 cout<<"我是A的析构函数,啦啦啦-----"<<endl; 13 }
结果: