I have a templated base class that provides a method remove(). I have a class derived from the templated base class that does not hide the remove() method. However, the templated based classes' remove method isn't visible. Why? And is there a way to resolve this (I mean other than the 'trick' I figured out at the very end)?
I've stripped this down to a small code example:
#include <map>
#include <iostream>
#include <boost/shared_ptr.hpp>
// Common cache base class. All our caches use a map, expect children to
// specify their own add, remove and modify methods, but the base supplies a
// single commont remove too.
template <class T>
class cache_base {
public:
cache_base () {};
virtual ~cache_base() {};
virtual void add(uint32_t id) = 0;
virtual void remove(uint32_t id) = 0;
void remove() {
std::cout << "This is base remove\n";
};
virtual void modify(uint32_t id) = 0;
protected:
typedef std::map< uint32_t, typename T::SHARED_PTR_T> DB_MAP_T;
DB_MAP_T m_map;
};
// A dummy item to be managed by the cache.
class dummy {
public:
typedef boost::shared_ptr<dummy> SHARED_PTR_T;
dummy () {};
~dummy () {};
};
// A dummy cache
class dummy_cache :
public cache_base<dummy>
{
public:
dummy_cache () {};
virtual ~dummy_cache () {};
virtual void add(uint32_t id) {};
virtual void remove(uint32_t id) {};
virtual void modify(uint32_t id) {};
};
int
main ()
{
dummy_cache D;
D.remove();
return(0);
}
This code fails to compile, giving me the following errors
g++ -g -c -MD -Wall -Werror -I /views/LU-7.0-DRHA-DYNAMIC/server/CommonLib/lib/../include/ typedef.cxx
typedef.cxx: In function 'int main()':
typedef.cxx:67: error: no matching function for call to 'dummy_cache::remove()'
typedef.cxx:54: note: candidates are: virtual void dummy_cache::remove(uint32_t)
make: *** [typedef.o] Error 1
I don't know if it makes a difference but I am using g++ version 4.1.2 20070115.
Also, I found that if I added the following remove method to the dummy_cache
it works. However, it feels odd that I have to add an a subordinate method in the dummy_cache to expose a public base method.
void remove () {return cache_base<dummy>::remove(); }