質問

私はプライベートネストされた実装が含まれている抽象基本クラスを持っています。私は非抽象ネストされた実装をインスタンス化しようとすると、Visual C ++が私に次のエラーを与えている。

エラーC2259: 'ノード:: empty_node':抽象クラスをインスタンス化することができない(ライン32)

私の知る限り、私は、基本クラスのすべての抽象メンバーをオーバーライドしてきました。

コードは次のとおりです。

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;
    }
};
役に立ちましたか?

解決

関数のシグネチャが一致しません。基底クラスの純粋仮想メンバ関数「ノード」がCONSTありません。派生クラスのempty_node '内の関数はconstのです。

あなたは、基本クラスの仮想関数のconstを作るか、派生クラスのメンバ関数からのconst修飾子を削除する必要がありますどちらか。

他のヒント

あなたのネストされたクラスはkeyvalueleftrightaddremovesearch方法の非constバージョンが欠落しています。

あなたのconst機能が優先されますされていません。

ライセンス: CC-BY-SA帰属
所属していません StackOverflow
scroll top