【发布时间】:2012-11-08 02:01:48
【问题描述】:
我对在 C++ 中的超类中引用子类有点困惑。 例如,给定 Java :
public class Entity {
protected ComplexEntity _ce;
public Entity() {
}
public ComplexEntity getCentity() {
return _ce;
}
}
ComplexEntity 扩展实体的地方。它可以工作。在子类中我调用 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
在继承自该实体的类中。为什么会发生这种情况?
在 C++ 中是完全不能接受的吗?
可能实体必须是抽象的? 我想就可能的解决方法获得建议。
【问题讨论】:
-
你有 C++ 代码要展示吗?
标签: c++ oop inheritance