【发布时间】:2022-06-15 21:50:16
【问题描述】:
我一直在研究一个简化的 STL:map
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));
}
};
基于AVL_Tree,而AVL继承自Binary_Search_Tree:
map.block: AVL -> BST
我收到了警告:
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();
【问题讨论】:
-
那不是警告,那是错误。它指的是您没有向我们展示的代码(特别是
binary_tree.h中的第 649 和 652 行)