The following code:
foo.h
#include "bar.h"
class foo{
public:
enum my_enum_type { ONE, TWO, THREE };
foo();
~foo() {}
};
foo.cpp
foo::foo()
{
int i = bar::MY_DEFINE;
}
bar.h
#include "foo.h"
class bar{
public:
static const int MY_DEFINE = 10;
foo::my_enum_type var;
bar() {};
~bar() {};
};
Makes g++ compiler complain about my_enum_type "does not name a type". Why ? All headers have multiple inclusion defines (not shown here for clarity).
Thanks
You must remove the cyclic dependency so you need to consider foo.cpp and foo.h as different units for this purpose.
bar class definition must see foo::my_enum_type so probably bar.h including foo.h is a necessity.
foo class definition does not use any of bar, so foo.h does not need to include bar.h
foo.cpp does need to see bar for MY_DEFINE so foo.cpp should include bar.h. That would actually also bring in foo.h automatically but you may wish to include it anyway in foo.cpp, just in case you remove the dependency later.
Presumably your headers have multiple include guards.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With