B
Brad Kartchner
I'm attempting to write a program with several child classes derived from a
single parent class. The parent class has a couple of variables that need
to be present in each of the child classes. However, I need the objects
created from each of the derived classes to share these variables with other
objects of the same class but not with other objects of the other derived
classes.
Let me try to clarify with an example:
//--------------------------------------------------------
class A // parent class
{
protected:
int Var1;
int Var2;
}
class B : public A // derived class 1
{
}
class C: public A // derived class 2
{
}
B ObjectB1;
B ObjectB2;
C ObjectC1;
C ObjectC2;
//--------------------------------------------------------
I would like ObjectB1 and ObjectB2 to share variable Var1 and Var2 with each
other, but ObjectC1 and ObjectC2 should share a completely different Var1
and Var2.
Is there a way to do this?
single parent class. The parent class has a couple of variables that need
to be present in each of the child classes. However, I need the objects
created from each of the derived classes to share these variables with other
objects of the same class but not with other objects of the other derived
classes.
Let me try to clarify with an example:
//--------------------------------------------------------
class A // parent class
{
protected:
int Var1;
int Var2;
}
class B : public A // derived class 1
{
}
class C: public A // derived class 2
{
}
B ObjectB1;
B ObjectB2;
C ObjectC1;
C ObjectC2;
//--------------------------------------------------------
I would like ObjectB1 and ObjectB2 to share variable Var1 and Var2 with each
other, but ObjectC1 and ObjectC2 should share a completely different Var1
and Var2.
Is there a way to do this?