我在C++中引用超类内的子类时有点困惑。 例如,给定的Java:超级类中的C++引用子类
public class Entity {
protected ComplexEntity _ce;
public Entity() {
}
public ComplexEntity getCentity() {
return _ce;
}
}
凡ComplexEntity扩展entity.It works.In子类我称之为getCentity()没有错误。
现在,C++,当我写类似的东西:
#pragma once
#include "maininclude.h"
#include "ExtendedEntity.h"
using namespace std;
class EntityBase
{
public:
EntityBase(void);
EntityBase(const string &name);
~EntityBase(void);
protected:
ExtendedEntity* _extc;
string _name;
};
我正在编译器错误:
error C2504: 'Entity' : base class undefined
在从该Entity.Why继承发生的呢类?
在C++中是完全不可接受的吗?
可能实体必须是抽象的吗? 我想获得有关可能的解决方法的建议。
你有任何C++代码显示? – jrok
请一分钟 –