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;
}

posted @ 2015-11-07 19:50  cloudren2020  阅读(94)  评论(0编辑  收藏  举报