在Map中使用Node, c++
Using Node in Map, C++
class MtmMap {
public:
class Pair {
public:
Pair(const KeyType& key, const ValueType& value) :
first(key),
second(value) { }
const KeyType first;
ValueType second;
};
class node {
friend class MtmMap;
Pair data;
node* next;
public:
node();
node(const Pair& pair){
data.Pair(pair.first , pair.second);
next = NULL;
}
};
node* temp = new node(pair);
}
错误:
没有匹配函数调用'mtm::MtmMap<int,>::Pair::Pair()'
无效使用'mtm::MtmMap<int,>::Pair::Pair'
from void mtm::MtmMap::insert(const
)mtm::MtmMap<KeyType,>::Pair&) [with KeyType = int;ValueType = int;
CompareFunction = AbsCompare]'
通过为Pair
定义一个带参数的构造函数,您删除了不带参数的隐式默认构造函数。当你在node
中有Pair
类型的成员时,它必须在节点的初始化列表中传递参数给它,你需要用以下方式替换你的节点构造函数:
node(const Pair& pair) : data(pair.first, pair.second) {
next = NULL;
}
将正确调用data
上的构造函数。Learn Cpp有一个关于初始化器列表如何工作的教程,你可能想要阅读。
首先映入我眼帘的是这一行:
node* temp = new node(pair);
看起来你试图在类定义中new
一个类。这可能是问题的一部分。另外,这个区域看起来有点混乱:
node(const Pair& pair){
data.Pair(pair.first , pair.second);
next = NULL;
}
看起来你试图直接调用Pair
构造函数。我不确定这对c++是否有效。实际上,只需像这样为Pair
定义一个复制构造函数:
Pair( Pair const& other )
: first( other.first )
, second( other.second )
{}
然后,该块变成
node( Pair const& pair )
: data( pair )
, next( NULL )
{}
您也可以检查std::pair
相关文章:
- node-gyp 在 macOS 上未正确链接库
- 为什么C++对链表中的下一个节点使用指针,而像 C# 或 Java 这样的语言只使用类 Node 的名称?
- node-gyp 的先有鸡还是先有蛋的问题:指向依赖项中的头文件
- 在 ubuntu 上安装 node js pulsar 客户端
- 如何使用 Node-addon-API 实现 node-nan 回调
- Node.js fs.open() 在尝试打开 4 个以上的命名管道 (FIFO) 后挂起
- NodeJS:node-gyp 编译与等效的 gcc -lm 选项
- 调用'Node'构造函数是不明确的
- 为什么我得到变量"Node"不是类型名称错误
- 在 node.js 中将缓冲区从 C++ 转换为 UTF-8 字符串
- 如何从 node-ffi 调用 c++ 中以结构向量作为参数的方法?
- 使用 Node.js N-API 调用 C 函数时,不会显示预期的输出
- 给一个图 G 找到此图中的所有节点 blob,以便 node.color 属性 = 特定颜色
- 为什么 const YAML::Node 对象的行为不像 yaml-cpp 中的类似值的对象?
- 无法使用 'const Node *' 类型的右值初始化 'Node *' 类型的变量
- Node中的子节点列表在C++中的BFS遍历过程中丢失
- 用输出参数包装一个c++函数,以便在javascript/node中使用
- 在node-gip binding.gyp文件中,如何根据系统结构(32位、64位)包含不同的库文件
- node.h/node.cpp/nodelist.cpp之间的关系
- 如何使用 v8 本机插件将 C++ 数组交付到 Node.js