摘要: explicit显示定义、禁止编译器隐式发生用户转换、如下class SmallInt {public: SmallInt(int i){}};class Number {public: Number(const SmallInt&);};如果不使用explicit的话、那么即使使用一个int的变量来初始化Number的构造函数也可以成立、编译器会首先调用SmallInt的构造函数、先使用int的变量初始化SmallInt、再把SmallInt的对象引用给Number的构造函数int ok = 0;Number(ok);但如果加上关键字explicit的话、这样编译是错误的!只能够.. 阅读全文
posted @ 2012-04-19 10:04 klobodnf 阅读(267) 评论(0) 推荐(0) 编辑