I'm using two classes that depend on each other. However, when I compile the program I get a nonsensical exception description. I have reduced my code to show the error only when I include the World.h
header file in the Creature
header file. The exception is thrown before an opportunity to implement a forward declaration, or template. Also, preprocessor directives are not working in my case.
Creature header:
#ifndef __CREATURE_H
#define __CREATURE_H
#include "World.h"
class Creature
{
public:
//World *world; -- This class only needs a pointer to world.
};
#endif
World header:
#ifndef WORLD_H
#define WORLD_H
#include "Creature.h"
class World
{
public:
Creature** world;
};
#endif
A Driver to complete the example:
#include "World.h"
int main()
{
World world;
return 0;
}
Visual Studio 2012's Exception message:
world.h(14): error C2143: syntax error : missing ';' before '*'
world.h(14): error C4430: missing type specifier - int assumed. Note: C++ does not support default-int
I noticed in my minimal example that Intellisense
will underline an inclusion and on hover show: "Include file .. includes itself". This doesn't happen in my larger project. However, commenting the include, uncommenting the instantiation of the other class, then compiling the project produces the same error.