简体   繁体   中英

No Matching Function Call Error for Template Constructor

Here is an excerpt of a class declaration:

template<typename key_type,typename value_type>
class _IndexTupleTree_Iterator
{
public:

    typedef typename std::vector<value_type>::iterator value_it_t;
    _IndexTupleTree_Iterator(std::vector<GenNode<key_type,value_type>*>& node_stack,std::vector<int>& key_pos_stack,value_it_t value_pos);
 ...
 }

I attempt to call the above constructor in the context below (last line):

template<typename key_type,typename value_type>
class LeafNode : public GenNode<key_type,value_type>
{
public:
    typedef std::pair< std::vector<key_type>,value_type > entry_t;
    LeafNode(const entry_t entry);
    void insert(const entry_t entry);
    _IndexTupleTree_Iterator<key_type,value_type> begin(std::vector<GenNode<key_type,value_type>*>& node_stack,std::vector<int>& key_pos_stack) const;
    bool operator==(const LeafNode<key_type,value_type>& rhs) const;
    //bool find(std::vector<key_type> key, _IndexTupleTree_Iterator& pos);
private:
    std::vector<value_type> _values;
};

 template<typename key_type,typename value_type>
_IndexTupleTree_Iterator<key_type,value_type> LeafNode<key_type,value_type>::begin(std::vector<GenNode<key_type,value_type>*>& node_stack,std::vector<int>& key_pos_stack) const
{
    key_pos_stack.push_back(0);
    return _IndexTupleTree_Iterator<key_type,value_type>(node_stack,key_pos_stack, _values.begin());
}

But I receive the following error:

../src/tensor_utils/IndexTupleTree.h:134: error: no matching function for call to ‘_IndexTupleTree_Iterator<int, int>::_IndexTupleTree_Iterator(std::vector<GenNode<int, int>*, std::allocator<GenNode<int, int>*> >&, std::vector<int, std::allocator<int> >&, __gnu_cxx::__normal_iterator<const int*, std::vector<int, std::allocator<int> > >)’
../src/tensor_utils/IndexTupleTree.h:55: note: candidates are: _IndexTupleTree_Iterator<key_type, value_type>::_IndexTupleTree_Iterator(std::vector<GenNode<key_type, value_type>*, std::allocator<GenNode<key_type, value_type>*> >&, std::vector<int, std::allocator<int> >&, typename std::vector<value_type, std::allocator<_T2> >::iterator) [with key_type = int, value_type = int]

I know that the problem is with the last argument. Does anyone know why it can't find the constructor and call it?

Does anyone know why it can't find the constructor and call it?

That is because your begin() function is const -qualified, which means that doing _values.begin() will return you a const_iterator .

However, the constructor of _IndexTupleTree_Iterator accepts a non- const iterator as the last argument. This is why the compiler cannot resolve the call.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM