定义对象指针时不执行构造函数吗?对象指针和对象有什么区别?
classobj{public:obj(void){cout<<"Initialization"<<endl;};~obj(void){cout<<"Destroy"<<...
class obj
{
public:
obj(void){cout<<"Initialization"<<endl;};
~obj(void){cout<<"Destroy"<<endl;};
void Initialize(void){cout<<"Initialization"<<endl;};
void Destroy(void){cout<<"Destroy"<<endl;};
};
int main(void)
{
obj *a;
a->Initialize();
a->Destroy();
cout<<endl;
obj b;
b.Initialize();
b.Destroy();
}
vc6.0 下的运行结果:
Initialization
Destroy
Initialization
Initialization
Destroy
难道obj *a;没有执行构造函数吗?,a->Initialize(); a->Destroy();能执行,怎么解释?
谢谢大家 展开
{
public:
obj(void){cout<<"Initialization"<<endl;};
~obj(void){cout<<"Destroy"<<endl;};
void Initialize(void){cout<<"Initialization"<<endl;};
void Destroy(void){cout<<"Destroy"<<endl;};
};
int main(void)
{
obj *a;
a->Initialize();
a->Destroy();
cout<<endl;
obj b;
b.Initialize();
b.Destroy();
}
vc6.0 下的运行结果:
Initialization
Destroy
Initialization
Initialization
Destroy
难道obj *a;没有执行构造函数吗?,a->Initialize(); a->Destroy();能执行,怎么解释?
谢谢大家 展开
1个回答
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询