explicit显示使用构造函数

来源:互联网 发布:php聊天软件源码 编辑:程序博客网 时间:2024/06/18 18:38
#include<iostream>using namespace std;/***关键词 explicit显式*应用:只能修饰构造函数*功能:防止构造函数被调用时,实参隐式转换数据类型**///double d=10;(隐式转换) 10.0class 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;}

0 0
原创粉丝点击