Error Does Not Name A Type Enum
Contents |
here for a quick overview of the site Help Center Detailed answers to any questions you might have Meta Discuss the workings and policies of this site About Us Learn more about Stack Overflow the company Business Learn more about using enum in class c++ hiring developers or posting ads with us Stack Overflow Questions Jobs Documentation Tags Users Badges class does not name a type Ask Question x Dismiss Join the Stack Overflow Community Stack Overflow is a community of 4.7 million programmers, just like you, helping each other.
C++ Enum
Join them; it only takes a minute: Sign up enum does not name a type up vote 4 down vote favorite I have a class Response say. #include "NetworkResponse.h" class NetworkResponse; class Response { public: Response(); virtual ~Response(); Response(NetworkResponse * networkResponse); NetworkResponses responseCode; // This is an enum and here I get an error }; #endif NetworkResponses is actually an enum defined in the "NetworkResponse.h". Like this: // "NetworkResponse.h": #include "Response.h" enum NetworkResponses { Success = 1, UserAlreadyExists = 2, InvalidUsername = 3, SecurityError = 4, UnknownError = 5 }; class Response; class NetworkResponse { public: NetworkResponse(); virtual ~NetworkResponse(); }; But I get an error: : "NetworkResponses does not name a type" in the Response class definition, when I try to compile. Can someone please help?? I think I am missing something simple. I think I was able to use this enum in other classes successfully, don't know what's wrong in this case... Thanks. c++ qt share|improve this question edited Feb 28 '13 at 12:19 asked Feb 28 '13 at 11:42 user2054339 157318 1 is it within the same namespace? –Zaid Amir Feb 28 '13 at 11:44 2 The only this I see, but which shouldn't cause any problem, is the semicolon after the second #include. Is it possible for you to create a SSCCE that have this problem and show us that? –Joachim Pileborg Feb 28 '13 at 11:45 One more thing here, is your enum and class declared in your header file in exactly the same order as you showed us here? –Zaid Amir Feb 28 '13 at 11:51 In your first snippet, you #include "Response.h";, which has a semicolon at the end and would cause an endless include recursion. Please show real code, otherwise we can only guess. –Olaf Dietsche Feb 28 '13 at 11:55 @RedSerpent yes same order, and btw. I don't use any namespaces –user2054339 Feb 28 '13 at 11:55 | show 2 more comments 3 Answers 3 active oldest votes up vote 6 down vote accepted You have a cyclic include dependency: NetworkResponse.h includes Respo
here for a quick overview of the site Help Center Detailed answers to any questions you might have Meta Discuss the workings and policies of this site About Us Learn more about Stack Overflow the company Business Learn more about hiring developers or posting ads with us Stack Overflow Questions Jobs Documentation Tags Users Badges Ask Question x Dismiss Join the Stack Overflow Community Stack Overflow is a community of 4.7 million programmers, just like you, helping each other. Join them; it only takes a minute: Sign up problem http://stackoverflow.com/questions/15134645/enum-does-not-name-a-type with enum "does not name a type' up vote 4 down vote favorite g++ (Ubuntu/Linaro 4.4.4-14ubuntu5) 4.4.5 I am having a problem and I seem to find out way I am getting this error. file statemachine.h #ifndef STATEMACHINE_H_INCLUDED #define STATEMACHINE_H_INCLUDED #include "port.h" enum state { ST_UNINITIALIZED = 0x01, ST_INITIALIZED = 0x02, ST_OPENED = 0x03, ST_UNBLOCKED = 0x04, ST_DISPOSED = 0x05 }; void state_machine(event evt, http://stackoverflow.com/questions/5700999/problem-with-enum-does-not-name-a-type port_t *port); #endif /* STATEMACHINE_H_INCLUDED */ file port.h #ifndef PORT_H_INCLUDED #define PORT_H_INCLUDED #include
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
2
3
4
5
6
7
8
enum UNIT { ALL, BIO, MECH, IMP, GHAST, PEGASUS, BEHEMOTH, EAGLE, PHOENIX }; enum does not name 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 ComplexityCos