C ++继承:在头中调用基类构造函数 [英] C++ Inheritance: Calling Base Class Constructor In Header
本文介绍了C ++继承:在头中调用基类构造函数的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
假设类 Child
是类 Parent
的派生类。在一个五文件程序中,我如何在 Child.h
中指定我要调用 Parent
的构造函数?我不认为下面是合法的标题内:
Assume class Child
is a derived class of the class Parent
. In a five file program, how would I specify in Child.h
that I want to call the constructor of Parent
? I don't think something like the following is legal inside the header:
Child(int Param, int ParamTwo) : Parent(Param);
在这种情况下,应该 Child.cpp
的构造函数语法看起来像?
In this situation, what should Child.cpp
's constructor syntax look like?
推荐答案
在Child.h中,您只需声明:
In Child.h, you would simply declare:
Child(int Param, int ParamTwo);
在Child.cpp中,您将有:
In Child.cpp, you would then have:
Child::Child(int Param, int ParamTwo) : Parent(Param) {
//rest of constructor here
}
这篇关于C ++继承:在头中调用基类构造函数的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文