explicit关键字加上该关键字就不允许隐式转化了 123456789101112131415161718class point{public: //explicit Point(int x = 0,int y = 0) :_ix(x) ,_iy(y) { }private: int _ix; int _iy;};void test(){ Point p = 1;//其实类似与 ClassName cn = "hello" //但是上面加上了explicit就不允许这样使用了} 文件输入流的无参构造函数 1234567891011121314#inlucde <fstream>ifstream ifs;//使用无参构造函数需要在调用open函数打开文件ifs.open("test.cc");//ifs本身也可以当作判断条件,如果打开成功就是good状态,也就是trueif(!ifs){ cerr << "ifstream open filed!" << endl; return;}//从文件中获取内容,将文件中的内容输入到内存中string world;ifs >> word;cout << word << endl;