Im a fairly new programmer so I may not be understanding typedef correctly.
I have 2 classes Enemy.cpp and AI.cpp. My AI.cpp needs values from Enemy.cpp to be able to process its movements etc. In AI.cpp I hold pointers to values such as position, speed and an enum for the direction the enemy is facing.
The Errors I get are listed below. If there is a more simple way to link an enum variable between classes, im all ears.
below is a working example of the error.
///////MAIN.H/////////////
#ifndef _MAIN_H_
#define _MAIN_H_
#endif // ! _MAIN_H_
///////////////////////////
////////MAIN.CPP///////////
#include "AI.h"
#include "Enemy.h"
int main(int argc, char* args[])
{
Enemy enemy;
}
//////////////////////////////
//////////ENEMY.H///////////////
#ifndef _ENEMY_H_
#define _ENEMY_H_
#include "AI.h"
class Enemy
{
public:
Enemy();
enum Facing
{
LEFT = 0,
RIGHT
};
protected:
AI* EnemiesAI;
//try this as a pointer
Facing EnemyDirection;
};
#endif
//////////////////////////////////
///////////ENEMY.CPP////////////////
#include "Enemy.h"
Enemy::Enemy()
{
EnemiesAI = new AI;
EnemiesAI->LinkEnemyToAI(&EnemyDirection);
}
////////////////////////////////////
/////////////////AI.H//////////////
#ifndef _AI_H_
#define _AI_H_
#include "Enemy.h"
class AI
{
public:
/*this needs to be a pointer, otherwise I have to pass the
value into AI on every update*/
typedef Enemy::Facing *ThisFacing; //Error 3
void LinkEnemyToAI(ThisFacing facing);
private:
//This is a pointer to a Enemy::Facing object
ThisFacing mFacing;
};
#endif
///////////////////////////////////////
////////////////AI.CPP/////////////////
#include "AI.h"
void AI::LinkEnemyToAI(ThisFacing facing)
{
mFacing = facing;
}
////////////////////////////////////////
Error C2653 'Enemy': is not a class or namespace name ExampleOfTypeDefError c:\dev\projects\exampleoftypedeferror\exampleoftypedeferror\ai.h 11
Severity Code Description Project File Line Error C4430 missing type specifier - int assumed. Note: C++ does not support default-int ExampleOfTypeDefError c:\dev\projects\exampleoftypedeferror\exampleoftypedeferror\ai.h 11
Severity Code Description Project File Line Error C3646 'mFacing': unknown override specifier ExampleOfTypeDefError c:\dev\projects\exampleoftypedeferror\exampleoftypedeferror\ai.h 17
Severity Code Description Project File Line Error C4430 missing type specifier - int assumed. Note: C++ does not support default-int ExampleOfTypeDefError c:\dev\projects\exampleoftypedeferror\exampleoftypedeferror\ai.h 17
Severity Code Description Project File Line Error C2660 'AI::LinkEnemyToAI': function does not take 1 arguments ExampleOfTypeDefError c:\dev\projects\exampleoftypedeferror\exampleoftypedeferror\enemy.cpp 7
Severity Code Description Project File Line Error C2061 syntax error: identifier 'ThisFacing' ExampleOfTypeDefError c:\dev\projects\exampleoftypedeferror\exampleoftypedeferror\ai.h 13
Severity Code Description Project File Line Error C2238 unexpected token(s) preceding ';' ExampleOfTypeDefError c:\dev\projects\exampleoftypedeferror\exampleoftypedeferror\enemy.h 23