#include <iostream>
using namespace std;
class A
{
public:
explicit A(int i){x=i;cout<<"调用构造函数"<<x<<endl;} //取消隐式转换关键字:explicit
~A(){cout<<"调用析构函数"<<x<<endl;}
void get(){cout<<x<<endl;}
private:
int x;
};
int main()
{
A a(6);
a.get();
//a=1000; //隐式转换,等价于:a=A(1000); //显示转换--->隐式转换报错
a=A(1000);
return 0;
}
显示结果为: