I have an abstract base class which contains a private nested implementation. visual c++ is giving me the following error when I try to instantiate the non-abstract nested implementation:
error C2259: 'node::empty_node' : cannot instantiate abstract class (line 32)
as far as I can tell, I've overridden all the abstract members of the base class
Code follows:
using namespace boost;
template<typename K, typename V>
class node {
protected:
class empty_node : public node<K,V> {
public:
bool is_empty(){ return true; }
const shared_ptr<K> key() const { throw empty_node_exception; }
const shared_ptr<V> value() const { throw empty_node_exception; }
const shared_ptr<node<K,V>> left() const { throw empty_node_exception; }
const shared_ptr<node<K,V>> right() const { throw empty_node_exception; }
const shared_ptr<node<K,V>> add(const shared_ptr<K> &key, const shared_ptr<V> &value) const {
return shared_ptr<node<K,V>>();
}
const shared_ptr<node<K,V>> remove(const shared_ptr<K> &key) const { throw empty_node_exception; }
const shared_ptr<node<K,V>> search(const shared_ptr<K> &key) const { return shared_ptr<node<K,V>>(this); }
};
static shared_ptr<node<K,V>> m_empty;
public:
virtual bool is_empty() = 0;
virtual const shared_ptr<K> key() = 0;
virtual const shared_ptr<V> value() = 0;
virtual const shared_ptr<node<K,V>> left() = 0;
virtual const shared_ptr<node<K,V>> right() = 0;
virtual const shared_ptr<node<K,V>> add(const shared_ptr<K> &key, const shared_ptr<V> &value) = 0;
virtual const shared_ptr<node<K,V>> remove(const shared_ptr<K> &key) = 0;
virtual const shared_ptr<node<K,V>> search(const shared_ptr<K> &key) = 0;
static shared_ptr<node<K,V>> empty(){
if(NULL == m_empty.get()){
m_empty.reset(new empty_node());
}
return m_empty;
}
};