Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

enum does not name a type

Tags:

c++

qt

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.

like image 971
user2054339 Avatar asked Feb 28 '13 11:02

user2054339


2 Answers

You have a cyclic include dependency: NetworkResponse.h includes Response.h and vice versa. This cannot work. NetworkResponse.h does not need to include Response.h at all, so you can remove that include.

like image 97
juanchopanza Avatar answered Oct 02 '22 11:10

juanchopanza


This enum has an underlying type, int in this case. So you can do the following:

int response = Success;

You can use it this way, too. See this.

like image 32
bash.d Avatar answered Oct 02 '22 13:10

bash.d