繁体   English   中英

C ++前向声明和不完整类型

[英]c++ forward declaration and incomplete type

您好,我无法使用前向声明。 尽管我需要访问转发的类函数,但我不能这样做。

这是我的Window.h:

#include "Tab.h"  // Needed because Window will create new Tabs

class Window {
  public:
    ...
    void doSome();

};

这是Tab.h:

class Window;  // forward delcaration

class Tab {

public:
  class Tab(Window *parent);
  void callParentFunction();

private:
  Window *m_parent;
};

最后,Tab.cpp:

#include "Tab.h"

Tab::Tab(Window *parent) {
  m_parent = parent;
}

Tab::callParentFunction() {
  m_parent->doSome();  // Error
}

编译器向我返回以下错误:不完整类型'struct Window'的无效使用

我知道父功能已经包含Tab.h才能创建选项卡,如何访问父功能? 如果我做不到,您建议我怎么做?

您需要定义Window类才能调用

 m_parent->doSome();

因此,在Tab.cpp包括Window.h

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM