我想知道从构造函数调用函数是否是好的编程? 例如:
class Foo{
Foo(){
function1();
}
void function1(){
}
};
最佳答案
如果你想要纯初始化函数,你可以在默认构造函数中处理(在某些情况下)
class C
{
C() { /* default init */ }
C(int a) : C() { /* do something extra with a */ }
C(const std::string& s) : C() { /* do something extra with s */ }
};
关于c++ - 在同一个类的构造函数中调用一个函数是好的编程吗?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/30631769/