0

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

错误说 No matching call to addSupport(NestedConnection<Paragraph, NestedConnection<Line, void> >*&)But the Candidates are 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*
4

1 回答 1

1

AT*可以const T*隐式转换为 a 但您不能将 a 绑定T*到 a const T*&。如果引用是const引用,您可以,例如const T* const&.

于 2012-08-07T05:42:17.157 回答