R: [Algorithms] Template Question...
Brought to you by:
vexxed72
From: Davide P. <zio...@li...> - 2000-12-31 12:16:08
|
template <class cType> class tTemplate { public: void CallProtectedFunc() { mType->ProtectedFunc(); } protected: cType *mType; }; =20 class cObject { protected: void ProtectedFunc(); =20 friend tTemplate; }; =20 >The above works for instances of cObject, but not for the derived = classes, where it generates an compiler error saying that >the protected = function cannot be accessed. Friend is not derivable, so you must add a friend declaration for = every derived class. (But it's ugly and nasty) BTW: why do not use a virtual pure function instead of template ? class cSoul { protected: void virtual ProtectedFunc() =3D 0; }; class cObject : public cSoul { protected: void virtual ProtectedFunc() { return; } } class cObject1 : public cObject { protected: void virtual ProtectedFunc() { return; } } So every class must define a ProtectedFunc that have a full class = access. |