explicit关键字 explicit用途: 防止利用隐式类型转换方式来构造对象 登录后复制 #define _CRT_SECURE_NO_WARNINGS #include<iostream> using namespace std; class MyString { public: MyString(char * str) { } //explicit用途: 防止利用隐式类型转换方式来构造对象 explicit MyString(int len) { } }; void test01() { MyString str1(10); MyString str2 = MyString(100); //MyString str3 = 10; // "10" } int main(){ test01(); system("pause"); return EXIT_SUCCESS; } 1.2.3.4.5.6.7.8.9.10.11.12.13.14.15.16.17.18.19.20.21.22.23.24.25.26.27.28.29.30.31.32.33.34.35.36.37. 原创作者: zaishu 转载于: https://blog.51cto.com/zaishu/11898343