explicit
来源:互联网 发布:js 人际关系图插件 编辑:程序博客网 时间:2024/05/12 15:21
explicit
C++ Specific
This keyword is a declaration specifier that can only be applied to in-class constructor declarations. Constructors declared explicit will not be considered for implicit conversions. For example:
class X {
public:
explicit X(int); //legal
explicit X(double) { //legal
// ...
}
};
explicit X::X(int) {} //illegal
An explicit constructor cannot take part in implicit conversions. It can only be used to explicitly construct an object. For example, with the class declared above:
void f(X) {}
void g(int I) {
f(I); // will cause error
}
void h() {
X x1(1); // legal
}
The function call f(i) fails because there is no available implicit conversion from int to X.
Note It is meaningless to apply explicit to constructors with multiple arguments, since such constructors cannot take part in implicit conversions.
C++ Specific
This keyword is a declaration specifier that can only be applied to in-class constructor declarations. Constructors declared explicit will not be considered for implicit conversions. For example:
class X {
public:
explicit X(int); //legal
explicit X(double) { //legal
// ...
}
};
explicit X::X(int) {} //illegal
An explicit constructor cannot take part in implicit conversions. It can only be used to explicitly construct an object. For example, with the class declared above:
void f(X) {}
void g(int I) {
f(I); // will cause error
}
void h() {
X x1(1); // legal
}
The function call f(i) fails because there is no available implicit conversion from int to X.
Note It is meaningless to apply explicit to constructors with multiple arguments, since such constructors cannot take part in implicit conversions.
- explicit
- explicit
- explicit
- explicit
- explicit
- explicit
- explicit
- explicit
- explicit
- explicit
- explicit
- explicit
- explicit
- explicit
- explicit
- explicit
- explicit
- explicit
- POJ 3450 Corporate Identity 、 POJ 3080 Blue Jeans
- 智能手机vs.桌面:SEO+Web开发重心转移?
- java 线程同步
- ALV控件内置功能码一览表
- android进程间通信:使用AIDL
- explicit
- Android 之 SystemService
- Android 之 远程图片获取和本地缓存
- Android 之 内存管理
- Mutex, semaphore, spinlock的深度解析
- Android 之 sms 短信
- Spinner控件的使用
- 肆:列(貳)
- Android UI 设计最佳实践