I almost have all my coding done for the project, but I keep running in to the same problems when I want to put it all together. The problem is that I include headers files in files that are in the same hierarchy and therefore I get compilation errors that some classes are defined more than once.
Take the following example:
Menu.hclass Menu{};MainMenu.h#include "Menu.h"class MainMenu : public Menu{};CharacterMenu.h#include "Menu.h"class CharacterMenu : public Menu{};
With my 13 week C++ experience I think this looks ok. But when I try to use my classes together in an other class:
Main.cpp#include "MainMenu.h"#include "CharacterMenu.h"
I get compilation errors saying that Menu has been defined more than once. Now I understand why the compiler is complaining, the definition of class Menu is copied in twice because the header is included in both menus. What I don't understand is how I should handle this.
I'm puzzled why this problem does not occur for iostream or string. I can include these on any level and the compiler will never complain about those, or so it seems.
I'm looking for some design guideline which will prevent me from making the error above. Is there such guideline? And I'm wondering what is different about the std header files.