【发布时间】:2011-06-12 22:30:05
【问题描述】:
我在这里遗漏了什么吗?还是有不允许这样做的原因?
// the class declaration
class MapImage : public MapEntity, public Vector2D {};
// the variable declaration
std::vector<MapImage> healthpacks;
// the function
void DrawItems(SDL_Surface *dest, std::vector<Vector2D> &items, SDL_Surface *image);
// the implementation
DrawItems(dest, healthpacks, healthpack_image);
由于 healthpacks 是 MapImage 类的 std::vector,并且 MapImage 具有基类 Vector2D,因此“std::vector healthpacks”不应与“std::vector &items”兼容,因为它们具有相同的基类?
【问题讨论】:
-
是的。你得到什么编译错误?
-
使用 <或反引号,这样您的 vector
就不会在问题文本中被错误解析( 被隐藏)。
标签: c++ class inheritance vector arguments