Reputation: 208
Alright, I'm working with a group of students programming a game, using Visual Studio 2015.
I have an enum class defined in the files DataTypes.h and DataTypes.cpp, however when I try to use them an a third file, AiFSM.cpp, I recieve a generic compiler error:
"objectType has no member 'TYPE_ENEMY_SHIP'"
I get the same issue if I use enum instead of enum class, except the error throw is:
"Identifier 'TYPE_ENEMY_SHIP' is undefined."
However, When I include the definition of the enum in AiFSM.cpp, the code compiles. This gave me the impression my includes were the source of the error, but I've rechecked and then retyped them (just in case), to no avail.
Could anyone please suggest what's causing the problem, please?
DataTypes.h:
#pragma once
#ifndef DATATYPES_H //Duel header guard to support other compilers
#define DATATYPES_H
enum class objectType;
DataTypes.cpp:
#include "stdafx.h"
#include "DataTypes.h"
enum class objectType {
...(Long list of enums omitted)
//NOW we have NPC classes
TYPE_ENEMY_SHIP,
TYPE_ENEMY_STATION,
...
TYPE_DESTROYED
};
AiFSM.h:
#pragma once
#ifndef AIFSM_H
#define AIFSM_H
#include "stdafx.h"
#include "DataTypes.h"
void enterFSM(objectType* type, FSMData* fsmData);
#endif
And finally, AiFSM.cpp:
#include "stdafx.h"
#include "DataTypes.h"
#include "AiFSM.h"
//Passes the data onto the appropriate state
void enterFSM(objectType* type, FSMData* fsmData) {
switch (*type) {
case objectType::TYPE_ENEMY_SHIP:
{break;} //TODO: Implement code
...(More case statements with identical errors.)
}
}
Upvotes: 0
Views: 1154
Reputation: 28499
You need to move the full enum class declaration to the DataTypes.h header file.
Upvotes: 1