2013年5月20日

[C++]关键字explicit

摘要: [C++标准程序库 2.2.6]通过关键字explicit的作用,我们可以禁止“单参数构造函数(single argument constructor)”被用于自动型别转换。class Stack { explicit Stack(int size); // Create stack with initial size};...Stack s;s = 40; // Oops, creates a new Stack for 40 elements and assigns it to s如果没有explicit,上面那个构造函数有能力将一个int自动转型为Stack。“自动型别转换”动... 阅读全文

posted @ 2013-05-20 19:08 Lo0ong 阅读(182) 评论(0) 推荐(0) 编辑

导航