In short, I have several classes and some of these use inheritance. The base classes allocate memory based on a variable stored in a derived class. There are also some functions in the base classes that require a variable in the derived class.
What I'm doing at the moment is storing a pointer to the derived class inside the base class. Construction code is in the function 'Construct' so that the pointer can be passed to the base class.
Here is an example:
// Definitions
struct Class1;
struct Class2
{
int iV2;
Class1 * ptrC1;
void Construct(Class1 * paraC1);
void Set();
};
struct Class1: public Class2
{
int iV1;
Class1(); // Constructor
};
// Functions
Class1::Class1()
{
Class2::Construct(this);
iV1 = 500;
};
void Class2::Construct(Class1 * paraC1)
{
ptrC1 = paraC1;
}
void Class2::Set()
{
iV2 = ptrC1->iV1;
}
// Entry point
void main()
{
Class1 one;
one.Set();
}