declared enum "does not name a type"

I have several enums declared. I then have several classes declared, all of which use these enums. When I compile, I get an error with one of the enums, called DTYPE, which says 'DTYPE' does not name a type. Here is the relevant code:

main program
1
2
3
4
5
6
7
8
9
10
11
12
13
#include <iostream>
#include <string.h>
using std::cout;	using std::cin;		using std::string;
#include <enums.cpp>
#include <class-item.hpp>

...more crap here...

int main()
{
	IntroMenu();
	return 0;
}


enums.cpp
1
2
3
4
5
6
7
8
enum UNIT { ALL, BIO, MECH, IMP, GHAST, PEGASUS, BEHEMOTH, EAGLE, PHOENIX };
enum ENERGYTYPE { SOLAR, METHANE, BATTERY };
enum UCAT { INF, MOB, AVI, ORG };
enum DOMAIN { ALL, GRD, AIR, SEA };
enum EQTYPE { CPU, STOCK, ENGINE, SENSOR, ARMOR, WEAPON };
enum DTYPE { NONE, AP, BALLISTIC, MISSILE, FLAME, LASER, STRIKE, LEVI };
enum STAT { TACT, CLOUT, EDU, MA };
enum FACTION { AGARTHA, ATLANTIS, PACIFICA };


class-item.hpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
class Item
{
    protected:
       unsigned int spaceCost, weightCost, complexityCost, techLevel;
       UNIT uoc;                // this enum compiles fine
       string name;

    public:
       Item();
       Item(unsigned int spaceCost, unsigned int weightCost, unsigned int complexityCost, unsigned int techLevel, UNIT uoc, string name);
       Item(UNIT,string);
       ~Item();

       unsigned int SpaceCost() const;
       unsigned int WeightCost() const;
       unsigned int ComplexityCost() const;
       unsigned int TechLevel() const;
       UNIT Uoc() const;
       void Name() const;

       virtual unsigned int HealthBonus() const {}
       virtual unsigned int ArmorBonus() const {}
       virtual DTYPE DefenseType() const {}         // here is where I get the error.

...more code...


I've searched Google and most problems with this error are stupid typos and simple mistakes, which I'm sure is also the case here, I just can't spot it.
Last edited on
class-item.hpp should include your enum file. Also, that enum file should be an .hpp, not a .cpp.
Also, it's #include <string> , without the .h.

As for your actual error...it might be because your virtual functions aren't actually returning values. Either make them return values or make them pure virtual (depending on which one you want). If that doesn't work...I don't know what the problem is then...Try using DTYPE somewhere else and see if it bugs there too.
There are some structural problems with the code. enums.cpp should be named enums.hpp (it is a header after all) and it should be included by class-item.hpp. You also can't use DOMAIN as an identifier, because unfortunately cmath defines a macro with that name. So your code wouldn't compile whenever you include cmath before enums.hpp in any module.
You also have ALL in both UNIT and DOMAIN, which isn't allowed and should not compile.
Hah! Problem solved. I didn't compile this program as a project, and the compiler was searching other project directories for the includes, one of which was titled "enums.cpp" and it was obviously not finding DTYPE in that file. I had it include the correct enums.cpp file and now it all works great.
You really should rename it "enums.hpp" as firedraco and Athar have said, since it is a header.
Topic archived. No new replies allowed.