作者热门文章
- android - RelativeLayout 背景可绘制重叠内容
- android - 如何链接 cpufeatures lib 以获取 native android 库?
- java - OnItemClickListener 不起作用,但 OnLongItemClickListener 在自定义 ListView 中起作用
- java - Android 文件转字符串
假设类 Child
是类 Parent
的派生类。在一个五文件程序中,我如何在 Child.h
中指定我想调用 Parent
的构造函数?我认为 header 中的以下内容不合法:
Child(int Param, int ParamTwo) : Parent(Param);
在这种情况下,Child.cpp
的构造函数语法应该是什么样的?
最佳答案
在 Child.h 中,您只需声明:
Child(int Param, int ParamTwo);
在 Child.cpp 中,您将拥有:
Child::Child(int Param, int ParamTwo) : Parent(Param) {
//rest of constructor here
}
关于C++ 继承 : Calling Base Class Constructor In Header,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/24047140/
我是一名优秀的程序员,十分优秀!