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