gpt4 book ai didi

c++ - 编译器错过了现有的重载

转载 作者:行者123 更新时间:2023-11-28 07:59:37 26 4
gpt4 key购买 nike

我无法指出 unmatched 的签名有任何区别和 available过载。

错误显示没有匹配调用 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*

最佳答案

T* 可以隐式转换为 const T* 但不能将 T* 绑定(bind)到 const T *&。如果引用是 const 引用,你可以,例如const T* const&.

关于c++ - 编译器错过了现有的重载,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/11839789/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com