简体   繁体   English

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

[英]c++ forward declaration and incomplete type

Hello I have trouble working with forward declaration. 您好,我无法使用前向声明。 I can't access the forwarded class function, though I need to do so. 尽管我需要访问转发的类函数,但我不能这样做。

Here is my Window.h: 这是我的Window.h:

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

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

};

Here is Tab.h: 这是Tab.h:

class Window;  // forward delcaration

class Tab {

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

private:
  Window *m_parent;
};

And lastly, Tab.cpp: 最后,Tab.cpp:

#include "Tab.h"

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

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

The compiler returns me the following error: invalid use of incomplete type 'struct Window' 编译器向我返回以下错误:不完整类型'struct Window'的无效使用

How can I access the parent's function knowing it already includes Tab.h to create tabs? 我知道父功能已经包含Tab.h才能创建选项卡,如何访问父功能? If I can't, what do you advise me to do? 如果我做不到,您建议我怎么做?

You need the definition of the Window class in order to call 您需要定义Window类才能调用

 m_parent->doSome();

So, include Window.h in Tab.cpp . 因此,在Tab.cpp包括Window.h

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

相关问题 前向声明和强制转换不完整类型C ++ - forward declaration and Cast incomplete type C++ 用C ++转发类声明,不完整类型 - Forward Declaration of class in C++, incomplete type C ++前向声明和“不允许不完整类型”错误 - C++ Forward declaration and 'Incomplete type is not allowed' error C ++类的前向声明和对不完整类型的无效使用 - c++ class forward declaration and invalid use of incomplete type 无效使用不完整类型/转发错误声明。 可能会错过抽象类吗? (C ++) - invalid use of incomplete type / forward declaration of errors. possible missuse of abstract class? (C++) c ++“不允许不完整的类型”访问类引用信息时出错(带有前向声明的循环依赖) - c++ “Incomplete type not allowed” error accessing class reference information (Circular dependency with forward declaration) 前向声明在 c++ 中不起作用。它表示不完整类型的初始化 - Forward declaration not working in c++. It says initialization of incomplete type C ++ boost :: mpl :: type前向声明 - C++ boost::mpl::type forward declaration 错误:成员访问的类型不完整:正向声明 - error: member access into incomplete type : forward declaration of 前向声明类/无效使用不完整类型 - Forward declaration of class / Invalid use of incomplete type
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM