explicit in c++
来源:互联网 发布:手机淘宝店名可以改吗 编辑:程序博客网 时间:2024/06/07 23:32
在很多库中可以看到这个c++的关键字,主要作用是修饰构造函数,不允许隐式转换,避免难以觉察的错误
下面是cppreference中的例子
struct A{ A ( int ) {} operator int() const { return 0; }};struct B{ explicit B(int) {} explicit operator int() const { return 0; }};int main(){ // A is has no explicit ctor / conversion, everything is fine A a1 = 1; A a2 ( 2 ); A a3 { 3 }; int na1 = a1; int na2 = static_cast<int>( a1 ); B b1 = 1; // Error: implicit conversion from int to B B b2 ( 2 ); // OK: explicit constructor call B b3 { 3 }; // OK: explicit constructor call int nb1 = b2; // Error: implicit conversion from B to int int nb2 = static_cast<int>( b2 ); // OK: explicit cast}
0 0
- C++, explicit
- c++-explicit
- explicit in c++
- Explicit, Implicit in FTPs
- [C++]explicit解释
- [C++]explicit解释
- [C++]explicit解释
- C++:explicit 关键字
- C++explicit关键字
- 【C++】explicit关键字
- explicit构造函数(C++)
- C++explicit关键字
- 【C++】explicit构造函数
- 【C++】explicit关键字
- C++explicit的用法
- 【C++】explicit关键字
- [C++]explicit构造函数
- C++explicit的使用
- Flask_wtf自定义 field样式(Placeholder, Style)、wtf.html、匹配 Bootstrap4、jinja2 quick_form
- 函数a的内部函数b被函数a外的一个变量引用的时候,就创建了一个闭包
- 浅析python 中__name__ = '__main__' 的作用
- eclipse不能自动编译生成class文件的解决办法
- BZOJ4715 囚人的旋律
- explicit in c++
- 电商大战的背后,需要怎样的技术支撑?
- Open CV学习记录(十九)—图片拼接
- 104. Maximum Depth of Binary Tree (Easy)
- 盘点当下最流行的 Java 工具
- Android Studio离线使用gradle
- 一些实用的 Laravel 小技巧
- slice()截取方法substring()字符串截取substr()字符串截取
- 黑马程序员:各学科学习路线图,简直是厉害了word哥