Templates and 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’
任何想法将不胜感激
在您的代码中,您正在尝试将临时引用绑定到非常量引用。这是不允许的。
复制构造函数的正确签名是:
class TMergeNode {
public:
inline TMergeNode(const TMergeNode &b); // copy constructor
// ^^^^^
相关文章:
- C++核心准则 C35 对于接口类"A base class destructor should be either public and virtual, or protected and nonv
- 为什么C++逐位AND运算符在不同大小的操作数中表现为这样
- 为什么 Clang 不允许"and"作为函数名称?
- 位阵列上的快速AND运算
- 是否可以在 C++03 中定义'move-and-swap idiom'等效项
- BoostPython and CMake
- OpenSSL BIO and SSL_read
- Gurobi GRBModel and GRBmodel in C++
- std::visit and std::variant usage
- SHBrowseForFolder with BIF_BROWSEFORCOMPUTER and SHGetPathFr
- Directx12 and keystrokes
- different between int **arr =new int [ n]; and int a[i][j]?
- C++ getenv and setenv
- Inference pytorch C++ with alexnet and cv::imread image
- Visual Studio 2019 C++ and std::filesystem
- 保证逻辑 AND 表达式中的函数调用
- python ctypes and C++ pointers
- C++ const char with .begin() and .end()
- Threads with Classes and std::packaged_task
- libgphoto2 and Visual Studio 2019