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

相关文章:

  • 2021-09-28
  • 2022-03-03
  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
猜你喜欢
  • 2022-01-14
  • 2021-08-04
  • 2021-11-11
  • 2021-12-03
  • 2022-01-24
相关资源
相似解决方案