void* 链表中的数据类型?
void* data type in linked list?
我正在尝试实现键值链表,所以我声明:
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 但值应该是什么?
如果我没理解错的话,你需要实现StatusType Add(void *DS, int key, void* value)
函数才能被C代码使用,但是你自己的实现可以使用C++。
在那种情况下,显而易见的选择是 std::map<int, void*>
。链表类型没有键。
要存储 void* 数据类型,您需要使用 - 等等 - void* 数据类型。像这样:node<int, void*>
.
我正在尝试实现键值链表,所以我声明:
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 但值应该是什么?
如果我没理解错的话,你需要实现StatusType Add(void *DS, int key, void* value)
函数才能被C代码使用,但是你自己的实现可以使用C++。
在那种情况下,显而易见的选择是 std::map<int, void*>
。链表类型没有键。
要存储 void* 数据类型,您需要使用 - 等等 - void* 数据类型。像这样:node<int, void*>
.