【问题标题】:No matching function for call to copy constructor调用复制构造函数没有匹配的函数
【发布时间】:2012-05-09 07:38:02
【问题描述】:

我有一个类 Graph,它的复制构造函数在 Graph.h 中声明如下:

template<typename Object,typename Weight>              
Graph<Object,Weight>::Graph(Graph<Object,Weight>& G)

在其他地方,我尝试使用它:

Graph<double,double> G = make_graph("dense.g");

...但它给了我以下错误:

time_trialsALIST.cpp:37: 错误: 没有匹配函数调用 `Graph::Graph(Graph)' Graph.h:142:注意:候选人是:Graph::Graph(Graph&) [with Object = double, Weight = double]

我不明白为什么会这样; make_graph 函数只返回一个 Graph:

Graph<double,double>  make_graph(string filename){...} 

我需要在某处使用“&”吗?

【问题讨论】:

标签: c++ no-match


【解决方案1】:

Read the answer here。换句话说,您缺少const,而不是&amp;。制作它:

template<typename Object,typename Weight>              
Graph<Object,Weight>::Graph(const Graph<Object,Weight>& G)

您不能将临时对象绑定到非常量引用。

【讨论】:

    猜你喜欢
    • 2014-10-11
    • 2015-09-21
    • 1970-01-01
    • 1970-01-01
    • 2013-10-31
    • 2013-07-23
    • 2020-01-22
    • 1970-01-01
    • 2013-05-26
    相关资源
    最近更新 更多