I was building a class in the same header file, thinking it would be small, as my code developed it needed to be put into more than one header/cpp file. My data structure relies in an enum which now is included in another header file. The compiler complains.
error C2653: 'EnumBox' : is not a class or namespace name
error C2065: 'PLAYERNAME' : undeclared identifier
error C2065: 'RANDOMNUMBER' : undeclared identifier
It worked when they were all classes which used my enum were in the same headerfile. What is going on? Extern doesn't seem to work with enums.
GameDataNetworkHelper.h
#pragma once
#ifndef GAMEDATANETWORKHELPER_H
#define GAMEDATANETWORKHELPER_H
#include "../RakNetP2PExample/NetworkHelper.h"
#include "../GameExample/NumberGuesser.h"
#include "BitStream.h"
#include "../RakNetP2PExample/GameData.h"
#include "..\ConsoleApplication1\RandomNumber.h"
#include "..\ConsoleApplication1\PlayerName.h"
class NumberGuesser;
class NetworkHelper;
class EnumBox
{
public:
static const enum GameDataType {GAMEDATA = 0, PLAYERNAME=1, RANDOMNUMBER=2};
};
//..some code which uses RandomNumber, and PlayerName
#endif
And RandomNumber.h
#pragma once
#ifndef RANDOMNUMBER_H
#define RANDOMNUMBER_H
#include "../RakNetP2PExample/NetworkHelper.h"
#include "../GameExample/NumberGuesser.h"
#include "BitStream.h"
#include "../RakNetP2PExample/GameData.h"
#include "GameDataNetworkHelper.h"
class RandomNumber : public GameData
{
public:
static const int randomNumberType = EnumBox::GameDataType::RANDOMNUMBER;
//.. some other code
};
#endif
PlayerName.h
#pragma once
#ifndef PLAYERNAME_H
#define PLAYERNAME_H
#include "../RakNetP2PExample/NetworkHelper.h"
#include "../GameExample/NumberGuesser.h"
#include "BitStream.h"
#include "../RakNetP2PExample/GameData.h"
#include "GameDataNetworkHelper.h"
class PlayerName : public GameData
{
public:
static const int playerNameType = EnumBox::PLAYERNAME;
//...some other code
};
#endif
I've tried also extern enum GameDataType {GAMEDATA =0, PLAYERNAME, RANDOMNUMBER};
EnumBox::RANDOMNUMBER- Chintan