Created
July 30, 2019 07:19
-
-
Save qiaoxu123/e1c2a60f1447814ff1591d5c1d67ff21 to your computer and use it in GitHub Desktop.
C++ 中explicit 参数的作用是为了防止C++函数在执行时进行隐式转换。下方代码会报错,注释部分不会报错。
[参考地址](https://blog.csdn.net/tiefanhe/article/details/11478901)
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include<iostream> | |
// class Base { | |
// public: | |
// Base() = default; | |
// Base(int num){}; | |
// private: | |
// int num; | |
// }; | |
class Base { | |
public: | |
Base() = default; | |
explicit Base(int num); | |
private: | |
int num; | |
}; | |
int main() { | |
Base obj = 10; | |
return 0; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment