【发布时间】:2021-10-21 22:16:45
【问题描述】:
我正在尝试实现键值链表,所以我声明:
template<class S, class T>
class node {
public:
S key;
T value;
}
现在我想支持这个功能:
StatusType Add(void *DS, int key, void* value)
{
// key - the key of the node
// value - pointer to the value of the node
}
我对使用哪个链表感到困惑,键应该是 int 但值应该是什么?
【问题讨论】:
-
为什么是
void*而不是template<class S, class T> Add(???, S key, T value);?DS是什么? -
node类是强类型的,而Add()方法是无类型的。这是一个奇怪的组合。你能解释一下为什么以及如何将 C++ 和 C 风格的代码混合在一起吗? -
目前还不清楚
void* DS的神秘论点是什么。这是否包含类型信息? -
当你说“现在我想支持这个功能”时,你的意思是“现在我想实现一个通用函数来将
node添加到由nodes 组成的链表中" ? -
既然你有一个 key/value 对,那么这个链表是不是某种映射?
标签: c++ class templates linked-list