Basically, I have two classes under two different header files. ToolBar
and NewMenu
(I will use the actual class names for my better understanding) Both of these classes are under namespace map
. Now I have the class NewMenu
declared inside of the class ToolBar
. However, I have a member function in NewMenu
, (HandleEvents(..., ToolBar& toolBar)
), that handles events, but has the class ToolBar
as a parameter in order to pass and edit certain information based on the event that happens. However, this seems to cause circular-dependency.
So basically... I started like this...
// ToolBar.h
#include "NewMenu.h"
namespace map
{
class ToolBar
{
private:
NewMenu myNewMenu;
public:
/* ... */
}
} // namespace map
//////////////////////////
// NewMenu.h
#include "ToolBar.h"
namespace map
{
class NewMenu
{
private:
/* ... */
public:
void HandleEvents(ToolBar& toolBar)
{
/* ... */
//Use ToolBar function
toolBar.tileMap.Create();
/* ... */
}
/* ... */
}
} // namespace map
However, this causes circular-dependency. So I then did some research trying to solve this and got something like this...
// ToolBar.h
#include "NewMenu.h"
namespace map
{
class ToolBar
{
private:
NewMenu myNewMenu;
public:
/* ... */
}
} // namespace map
//////////////////////////
// NewMenu.h
//#include "ToolBar.h"
namespace map
{
class ToolBar; //(I presume) to make a temporary reference to class ToolBar.
class NewMenu
{
private:
/* ... */
public:
void HandleEvents(ToolBar& toolBar)
{
/* ... */
//Use ToolBar function
toolBar.tileMap.Create(); //Error: incomplete type is not allowed
/* ... */
}
/* ... */
}
} // namespace map
I'm not 100% sure, but based off of what I gathered, this should basically fix it(?), however, now I get an error in the HandleEvents()
function saying "Error: incomplete type is not allowed." So my question is, what am I getting wrong and how do I fix this circular dependency?
(side note: I got some of my research here. Though sometimes I just need things shown a slightly different way to understand)
Thank you for your time and help.