求大神解答,很急
#include<iostream>
using namespace std;
class Human{
public:
Human(){cout<<"構造函數執行中。。。"<<endl;i=999;}
~Human(){cout<<"析構函數執行中。。。。"<<endl;}
int get()const{return i;}
private:
int i; ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ?//執行結果為什么是構造函數執行中
? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? 構造函數執行中 ? ?
?}; ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ?析構函數執行中
? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? 析構函數執行中,為什么執行2遍啊,我認為只執行了一遍
int main(){
Human wlh;
wlh.get();
Human *p=new Human;
delete p;
return 0;
}
2015-04-21
你有兩個Human啊,wlh和p指向的那個new出來的Human。