mercredi 15 juin 2022

C++ : Error cannot call member function without object

I have been working on a simplified STL: map<Key,Val,Comp>

template <typename Key, typename Value, class Compare = pls<pair<Key, Value>>>
    class map // nuts::less<pair<Key, Value>>
    {
    protected:
        AVL<pair<Key, Value>, Compare> block;

    public:
        map() = default;
        ~map() { block.clear(); }

        u64 size() const { return block.size(); }
        bool empty() const { return block.empty(); }

        bool insert(const Key &_k, const Value &_v)
        {
            return block.insert(make_pair(_k, _v));
        }
    };

Which is based on AVL_Tree, and the AVL is inherited from Binary_Search_Tree:

 map.block: AVL -> BST

And I got a warning:

map.h:33:50:   required from 'bool nuts::map<Key, Value, Compare>::insert(const Key&, const Value&) [with Key = int; Value = int; Compare = nuts::pls<nuts::pair<int, int> >]'
main.cpp:66:16:   required from here
binary_tree.h:649:21: error: cannot call member function 'bool nuts::binary_tree<T, Compare>::insert(const T&) [with T = nuts::pair<int, int>; Compare = nuts::less<nuts::pair<int, int> >]' without object
   if (BST<T>::insert(_val))
       ~~~~~~~~~~~~~~^~~~~~
binary_tree.h:652:31: error: cannot call member function 'nuts::binary_tree<T, Compare>::const_iterator nuts::binary_tree<T, Compare>::find(const T&) [with T = nuts::pair<int, int>; Compare = nuts::less<nuts::pair<int, int> >]' without object
    node_ptr loc = BST<T>::find(_val).get();

Aucun commentaire:

Enregistrer un commentaire