explicit显示使用构造函数
#include<iostream>
using namespace std;
/**
*关键词 explicit显式
* 应用:只能修饰构造函数
* 功能:防止构造函数被调用时,实参隐式转换数据类型
**/
//double d=10;(隐式转换) 10.0
class Test
{
public:
explicit Test(int n) {//显式构造函数
cout<<"Test() n="<<n<<endl;
}
~Test(){}
};
int main(int argc,char**argv)
{
Test t1(10);
//Test t2=20;//无名对象
Test t3('a');
return 0;
}