码迷,mamicode.com
首页 > 其他好文 > 详细

explicit

时间:2014-08-30 20:27:09      阅读:169      评论:0      收藏:0      [点我收藏+]

标签:style   sp   on   new   size   c   as   bs   rom   

关键字explicit可以禁止单参数构造函数被用于自动类型转换
class Stack
{
explicit Stack(int size);
};
没有explicit的话Stack s = 40;能编译通过
而有explicit则不能,必需Stack s(40);

 

即防止构造函数进行的隐式转换的发生

explicit

标签:style   sp   on   new   size   c   as   bs   rom   

原文地址:http://www.cnblogs.com/notlate/p/3946784.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!