1

这是类声明的摘录:

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);
 ...
 }

我尝试在下面的上下文中调用上述构造函数(最后一行):

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());
}

但我收到以下错误:

../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]

我知道问题出在最后一个论点上。有谁知道为什么它找不到构造函数并调用它?

4

1 回答 1

3

有谁知道为什么它找不到构造函数并调用它?

那是因为你的begin()函数是const-qualified,这意味着做_values.begin()会返回一个const_iterator.

但是,构造函数_IndexTupleTree_Iterator接受一个非const iterator作为最后一个参数。这就是编译器无法解析调用的原因。

于 2013-06-15T18:26:59.127 回答