Sign in to follow this  

C++ error: expected class-name before ',' token

This topic is 2642 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

I'm having a problem with inheritance.
I want 'World' to inherit from 'Entity', but it seems as 'World' isn't recognizing 'Entity'. It is well typed, included, and on the same namespace.

Here is World.h

#ifndef WORLD_H
#define WORLD_H

#include "cg/cg.h"
#include "Entity.h"

namespace target {

class World : public Entity, public cg::Entity, public cg::IDrawListener, public cg::IUpdateListener {

private:
...
public:
...
};
}

#endif



and here is Entity.h
#ifndef ENTITY_H
#define ENTITY_H

#include "cg/cg.h"
namespace target {

class Entity {
public:
void toggleDebugMode();
};
}

#endif


the error is:

World.h:9: error: expected class-name before ',' token

The unrecognized class name is "Entity" (not cg::Entity)

Share this post


Link to post
Share on other sites
Check whether ENTITY_H gets defined directly or indirectly in "cg/cg.h". E.g. so in Entity.h:

#ifdef ENTITY_H
#error "duplicate ENTITY_H"
#endif

#ifndef ENTITY_H
#define ENTITY_H

#include "cg/cg.h"
namespace target {

class Entity {
public:
void toggleDebugMode();
};
}

#endif

When compiling World.h and the error message occurs, target::Entity will not declared.

Share this post


Link to post
Share on other sites
Sign in to follow this