繁体   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