c++ - Change type of base class variable in controlled situation? -
suppose:
class { public: *parent; }; class b : public { protected: b *bparent; };
but both 'parent' , 'bparent' in , b need occupy same memory space ! bparent in b 'is' in fact a, b objects parent b well, , makes easier access b-only functions , variables, without need cast parent b time in b , b inheriting classes , without need have virtualized in may needed in b.
is possible ? next doesn't work, there similar does work ?
class b : public { protected: union { a::parent ; b *bparent; }; };
i'd rather avoid:
class { public: union { *parent ; class b *bparent ; }; };
which work. utilize latter method if there way create bparent private in , still access in b, it's hidden non-b objects inherit a.
not exclusively sure you're asking here's go.
i'm guessing want save sort of access parent inherited works derived types.. maybe you're looking this:
template <class t> class { private: t *parent; }; class b : public a<b> { };
but seems want preserve , b...
so maybe you're looking this:
class { protected: *aparent() { homecoming parent; } protected: *parent; }; class b : public { protected: b *bparent() { homecoming (b*)parent; }; };
note if want utilize same memory both must same. casting pointers should want.
c++ class casting borland-c++
No comments:
Post a Comment