【发布时间】:2011-12-12 09:08:05
【问题描述】:
我的标题“figure.h”中有 Figure 类:
class Figure
{
Color color;
std::string position;
...
};
我想在标题“king.h”中定义一个 King 类。所以在king.h我做
#include "figure.h",并为 ex 写:
class King : public Figure
{
char type;
bool checkIfTypeIsValid(std::string);
...
};
但这似乎不起作用,因为 King 不认识 Figure... 我该怎么办?为不同的继承类设置不同的标头是否明智,或者只是将它们放在“figure.h”中?因为我还会有皇后、主教等人物,这将产生相当多的标题和暗示。文件..
【问题讨论】:
-
你说的金不认图是什么意思。
-
这应该可以,你可能在其他地方有错误。命名错误?
标签: c++ class inheritance header polymorphism