Is there a way to hide only some of the public members of a base class? It so happens that my child class makes it dangerous to access some of the members of the base class, but not all. My code is:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18
template <class Object>
class ListBasicObjects
{
public:
Object* TheObjects;
void AddObjectOnTop(Object& o);
};
//In the class below I want to hide the
//AddObjectOnTop function but still have TheObjects
//remain as public
template <class Object>
class HashedListBasicObjects : public ListBasicObjects<Object>
{
public:
void AddObjectOnTopHash(Object& o);
};
Don't try to "hide" the parent class's functions. Make them virtual and give the child class its own definitions:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17
template <class Object>
class ListBasicObjects
{
public:
Object* TheObjects;
virtualvoid AddObjectOnTop(Object& o);
};
// child which redefines AddObjectOnTop
// presumably, this version would do a hashing process (no need to
// rename the function to 'AddObjectOnTopHash')
template <class Object>
class HashedListBasicObjects : public ListBasicObjects<Object>
{
public:
virtualvoid AddObjectOnTop(Object& o);
};
I also need to call the base class function from the child ( but in a specific/tricky fashion, as the name of the child class suggests). What is the syntax for that?