编译器错过了现有的重载

时间:2012-08-07 05:31:35

标签: c++ templates

我无法指出unmatchedavailable重载的签名有任何区别。

错误表示没有与addSupport(NestedConnection<Paragraph, NestedConnection<Line, void> >*&)的匹配调用但是候选人是addSupport(const NestedConnection<Paragraph, NestedConnection<Line, void> >*&)他们可以隐式转换为const

error: no matching function for call to ‘NestedConnection<Section, NestedConnection<Paragraph, NestedConnection<Line, void> > >::addSupport(NestedConnection<Paragraph, NestedConnection<Line, void> >*&)’
note: candidates are: void Collection<T>::addSupport(const T*&) [with T = NestedConnection<Paragraph, NestedConnection<Line, void> >]

这就是我正在做的事情

template<typename T>
class Collection{
  public:
    typedef T Type;
    typedef std::vector<T*> CollectionT;
    typedef Collection<T> self;
  private:
    CollectionT _supports;
  public:
    void addSupport(const T*& connection){_supports.push_back(connection);};
    const CollectionT& supports() const{return _supports;}
};

template<typename T, typename C=void>
class NestedConnection: public Connection<T>, Collection<C>{
  public:
    typedef T ParentT;
    typedef C ChildT;
    typedef Connection<T> ConnectionT;
    typedef Collection<C> CollectionT;
    enum{
      leaf = 0
    };
  public:
    NestedConnection(const T* l, const T* r): Connection<T>(l, r){}
};

我正在调用

NestedConnection<ParentT, ChildT>* connection = new NestedConnection<ParentT, ChildT>(lhs, rhs);
//This will be unfolded till void and it starts from 
//NestedConnection<Section, NestedConnection<Paragraph, NestedConnection<Line, void>>>
connection->addSupport(con_lr);
//con_lr:ChildT*

1 个答案:

答案 0 :(得分:1)

T*可以隐式转换为const T*但您无法将T*绑定到const T*&。如果引用是const引用,则可以,例如const T* const&