Constructor函数中的explicit
来源:互联网 发布:权力的游戏 mac 编辑:程序博客网 时间:2024/05/18 01:30
class T {private:int a;double b;string c;public:T() :a(1), b(1), c("none") {}T(int n) :a(n) {}T(double d) :b(d) {}T(string s) : c(s) {}void print() {cout << a << endl;cout << b << endl;cout << c << endl;}};int main() {T x;x = 10.8; //this line will invokes from T(double d) :b(d) {}, and creates a temporary class T object, then x will be memberwise-copied by this object, all values of x from defination will be replaced.x.print();system("pause");return 0;}
class T {private:int a;double b;string c;public:T() :a(1), b(1), c("none") {}T(int n) :a(n) {}explicit T(double d) :b(d) {}T(string s) : c(s) {}void print() {cout << a << endl;cout << b << endl;cout << c << endl;}};int main() {T x;x = 10.8; // invokes from T(int n) :a(n) {}, 10.8 -> 10.x.print();system("pause");return 0;}
class T {private:int a;double b;string c;public:T() :a(1), b(1), c("none") {}explicit T(int n) :a(n) {}explicit T(double d) :b(d) {}T(string s) : c(s) {}void print() {cout << a << endl;cout << b << endl;cout << c << endl;}};int main() {T x;x = 10.8; // error, because explicit turns off implicit conversions.x.print();system("pause");return 0;}
0 0
- Constructor函数中的explicit
- explicit constructor(显示构造函数)
- explicit constructor的用法
- C++ 中的explicit构造函数
- C++ 中的关键字-------explicit 修饰构造函数
- c++ explicit在构造函数中的应用
- no copy constructor available or copy constructor is declared 'explicit'
- C++中的转换函数、explicit关键字与non-explicit-one-argument构造函数
- c++中的构造函数上explicit的作用
- C++ explicit在构造函数中的作用解析
- 《C++ primer》学习笔记之三十:explicit constructor
- 构造函数(constructor)
- virtual constructor 虚析构函数
- 构造函数CONSTRUCTOR
- 构造函数constructor
- javascript中的constructor
- Java中的constructor
- Java中的constructor
- 关于Struts2的namespace的一些总结
- android 安卓4.4 5.0 5.1 6.0支付flash的源码支持as2.0 flash
- IOS基础点总结
- JOB语句
- Android studio 使用---代码混淆和破解apk
- Constructor函数中的explicit
- SVN服务器框架搭建和代码填充(SVN简单版)
- AIX root 密码丢失解决办法
- 大气压、绝压、表压、真空度认识与理解
- ToDo
- Quartz任务调度
- 在windows下打开关闭外部应用程序的方法。
- Git常用操作命令收集
- Ajax分页