簡體   English   中英

在父類中調用方法

[英]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"

這次孩子可以看到父母,但是當我包括childbase時,我對父母卻產生了錯誤,因為他們彼此包括了

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.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM