基类与派生类的构造函数调用问题

来源:互联网 发布:搜狗大数据 编辑:程序博客网 时间:2024/05/22 14:25

class Core{public:Core(void);Core(std::istream& );};

class Grad :public Core{public:Grad(void);Grad(std::istream& );};

Grad类派生自Core

int main (int __argc, int __argv){Grad grad(cin);}
执行结果:
__thiscall Core::Core(void)__thiscall Grad::Grad(class std::basic_istream<char,struct std::char_traits<char> > &)

Grad类的两个构造函数,只要不在初始化的时候显示的调用基类(Core)的构造函数,编译器将调用基类默认构造函数(Core::Core())来构造对象的基类部分。

知道真相的我,哭眼泪掉下来,为什么Grad grad(cin)时,不能智能的调用基类的Core::Core(std::istream&)构造函数呢?

0 0
原创粉丝点击