Hi,
i have a StuffProducer(SProd) and a StuffContainer(SCont) basis class.
-SProd produces values, that are stored in SCont.
-Derived classes of both are compatible only on the same derivated
path.(SProdA with SContA, SProdB with SContB and so on ).
SProd should have always a intance of its respective Container as a
private variable.
My question is: how can i ensure that ppl who derive from it do
instantiate a Derived container within the producer?
pure virtual functions do make sure ppl will write the body for the
function...
i was thinking of placing a pointer of the base container class in the
base producer class (both abstract base classes (ABCs) ) and hope ppl
wont forget to set this pointer to the right derivation... well the
"right" derivation is not that important as to a derivation at all.
Some implemented member functions assume the pointer has been
asignated!
Example:
//******************
class SCont{};
class SProd{
protected:
SCont * pContainer;
void func(){//pContainer is used here!!};
};
//now comes the ideal implementation
class SContA:SCont{};
class SProdA:SProd{
private:
SContA contA;
pContainer = &contA; // <=This must happen!!!
}
//******************
is it ok to let it this way and tell everybody not to forget to assign
an object to the pointer or can i make sure the pointer will be set?
i could put a "if (pContainer=NULL) ERROR" on the members... but there
must be a more 1337 solution ;)
anyway thanks for any hint!!