[英]Calling a method in a parent class
經過一番搜索后,我了解到可以像這樣調用父方法:
基類:
class Base
{
public:
Base();
child *children; // instance of the child is needed on the base
float theDelegate(char *arg);
然后孩子上課:
class child: public Base //**** problem
{
public:
...
但是,當我嘗試添加public Base
行時,出現一個錯誤,他不知道Base
。
因此,我將base
包括在child
base
上 :
#include "Base.hpp"
這次孩子可以看到父母,但是當我包括child
的base
時,我對父母卻產生了錯誤,因為他們彼此包括了 。
child *children; - unknown type name child - appear only if I include parent in the child
我在這里做錯了什么? 應該怎么做?
使用前向聲明:
文件Base.hpp:
class Child; // forward declaration
class Base {
public:
Child* child;
// whatever
};
文件Child.hpp:
#include "Base.hpp"
class Child : public Base {
// whatever
};
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.