Please,look at this simple class:
class TernaryPolynomial;
class IntegerPolynomial;
class DenseTernaryPolynomial:public IntegerPolynomial,public TernaryPolynomial
{
public:
DenseTernaryPolynomial();
static DenseTernaryPolynomial generateRandom(int,int,int);
};
Can you please explain me why does the compiler complains that TernaryPolynomial must be a previously defined class or struct? I thought it shouldn’t care at all since i put a forward declaration of that class.
Here’s the TernaryPolynomial class
class Polynomial;
class IntegerPolynomial;
class TernaryPolynomial:public Polynomial
{
public:
TernaryPolynomial();
virtual ~TernaryPolynomial();
virtual IntegerPolynomial toIntegerPolynomial() = 0;
};
For derivation a forward declaration is not enough, you need to include the full class definition.
Forward declarations can only be used when you define a pointer or a reference to the class as a member or method parameter. As soon as you really begin using things (by dereferencing, accessing a member over a reference or deriving for example) you need to include the whole class definition.