somebody else女生唱的:C++中,什么叫显式调用?什么叫隐式调用?最好能举个例子

来源:百度文库 编辑:高考问答 时间:2024/05/03 23:05:05

#include <iostream>
using namespace std;

class A{
int x;
public:
A(){x=0;cout<<"Create A:0"<<endl;}
A(int a){x=a;cout<<"Create A:"<<x<<endl;}
~A(){cout<<"Delete A:"<<x<<endl;}
};

void main()
{
A a1;
A *a2=new A(10);
delete a2;
}

这个程序中:
A a1; 隐式调用了A()
A *a2=new A(10);显式调用了A(int a)
delete a2;以及程序结束时都隐式调用了析构函数~A()