Reputation: 193
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:
#include "Tab.h" // Needed because Window will create new Tabs
class Window {
public:
...
void doSome();
};
Here is Tab.h:
class Window; // forward delcaration
class Tab {
public:
class Tab(Window *parent);
void callParentFunction();
private:
Window *m_parent;
};
And lastly, 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'
How can I access the parent's function knowing it already includes Tab.h to create tabs? If I can't, what do you advise me to do?
Upvotes: 2
Views: 877
Reputation: 227370
You need the definition of the Window
class in order to call
m_parent->doSome();
So, include Window.h
in Tab.cpp
.
Upvotes: 6