請看看這個簡單的類:「類名」必須是以前定義的類或結構
class TernaryPolynomial;
class IntegerPolynomial;
class DenseTernaryPolynomial:public IntegerPolynomial,public TernaryPolynomial
{
public:
DenseTernaryPolynomial();
static DenseTernaryPolynomial generateRandom(int,int,int);
};
能否請您給我解釋一下,爲什麼編譯器抱怨TernaryPolynomial必須是以前定義的類或結構?我認爲它不應該在意,因爲我提出了該類的前瞻性聲明。 這裏的TernaryPolynomial類
class Polynomial;
class IntegerPolynomial;
class TernaryPolynomial:public Polynomial
{
public:
TernaryPolynomial();
virtual ~TernaryPolynomial();
virtual IntegerPolynomial toIntegerPolynomial() = 0;
};
相似:http://stackoverflow.com/questions/389957/forward-declaration-of-a-base-class – 2012-01-10 21:30:28