Skip to content

Instantly share code, notes, and snippets.

@qiaoxu123
Created July 30, 2019 07:19
Show Gist options
  • Save qiaoxu123/e1c2a60f1447814ff1591d5c1d67ff21 to your computer and use it in GitHub Desktop.
Save qiaoxu123/e1c2a60f1447814ff1591d5c1d67ff21 to your computer and use it in GitHub Desktop.
C++ 中explicit 参数的作用是为了防止C++函数在执行时进行隐式转换。下方代码会报错,注释部分不会报错。 [参考地址](https://blog.csdn.net/tiefanhe/article/details/11478901)
#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