繁体   English   中英

模板和g ++ 4.7

[英]Templates and g++ 4.7

我有这个代码

namespace MSL{

template <typename T> class TListNode;
template <typename T> class TList;
...

template <typename T> 
int TList<T>::add(T v) {
TListNode<T>  *pn;  
pn = new TListNode<T>;
...

class TMergeNode {
 public:

 inline      TMergeNode(int cluster1=-1, int cluster2=-1, TCMData mergeVal=0);
 inline      TMergeNode(TMergeNode &b);                // copy constructor
 ...

使用旧版本的g ++编译就可以了,但是现在使用4.7版,我得到以下错误:

./msl/MSL_List_Template.h: In instantiation of ‘int MSL::TList<T>::add(T) [with T = TMergeNode]’:
clustermerges.cpp:282:33:   required from here
./msl/MSL_List_Template.h:616:23: error: no matching function for call to ‘TMergeNode::TMergeNode(TMergeNode)’
./msl/MSL_List_Template.h:616:23: note: candidates are:
In file included from main.cpp:78:0:
clustermerges.cpp:70:8: note: TMergeNode::TMergeNode(TMergeNode&)
clustermerges.cpp:70:8: note:   no known conversion for argument 1 from ‘TMergeNode’ to ‘TMergeNode&’
clustermerges.cpp:68:8: note: TMergeNode::TMergeNode(int, int, MSL::TCMData)
clustermerges.cpp:68:8: note:   no known conversion for argument 1 from ‘TMergeNode’ to ‘int’

任何想法将不胜感激

在您的代码中,您尝试将临时绑定到非const引用。 这是不允许的。

复制构造函数的正确签名为:

class TMergeNode {
public:
 inline      TMergeNode(const TMergeNode &b);                // copy constructor
 //                     ^^^^^    

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM