C++题目,请问这个输出结果是什么?为什么?
#include<iostream>#include<string>usingnamespacestd;classCreateAndDestroy{public:Crea...
#include <iostream>
#include<string>
using namespace std;
class CreateAndDestroy
{
public:
CreateAndDestroy(int value, char str[20]){
data=value;
strcpy(memo,str);
cout<< "Object "<<memo<<" constructor"<<endl;
}
~CreateAndDestroy(){
cout<<"Object "<<memo<<" destructor "<<endl;
}
private:
int data;
char memo[20];
};
CreateAndDestroy first( 1," first " );
void create( void ){
CreateAndDestroy fifth( 3," fifth " );
}
int main(){
create();
CreateAndDestroy fourth( 2," fourth " );
return 0;
} 展开
#include<string>
using namespace std;
class CreateAndDestroy
{
public:
CreateAndDestroy(int value, char str[20]){
data=value;
strcpy(memo,str);
cout<< "Object "<<memo<<" constructor"<<endl;
}
~CreateAndDestroy(){
cout<<"Object "<<memo<<" destructor "<<endl;
}
private:
int data;
char memo[20];
};
CreateAndDestroy first( 1," first " );
void create( void ){
CreateAndDestroy fifth( 3," fifth " );
}
int main(){
create();
CreateAndDestroy fourth( 2," fourth " );
return 0;
} 展开
展开全部
Object first constructor //CreateAndDestroy first( 1," first " ); 调用构造函数
Object fifth constructor //CreateAndDestroy fifth( 3," fifth " ); 调用构造函数
Object fifth destructor //fifth对象随着函数的结束而消亡,调用析构函数
Object fourth constructor //CreateAndDestroy fourth( 2," fourth " ); 调用构造函数
Object fourth destructor //程序结束时调用析构函数
Object first destructor //程序结束时调用析构函数
Object fifth constructor //CreateAndDestroy fifth( 3," fifth " ); 调用构造函数
Object fifth destructor //fifth对象随着函数的结束而消亡,调用析构函数
Object fourth constructor //CreateAndDestroy fourth( 2," fourth " ); 调用构造函数
Object fourth destructor //程序结束时调用析构函数
Object first destructor //程序结束时调用析构函数
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询