【发布时间】:2014-11-22 03:02:30
【问题描述】:
我正在制作一个哈希表,我的类 HashTable 在我的头文件中包含以下结构和以下函数:
class HashT
{
public:
struct Node
{
std::string key;
std::string value;
Node* next;
};
Node** HashTArray;
void HashTCopy(struct Node** h1, struct Node** h2, unsigned int sz);
HashT(const HashT& hm); (copy constructor that calls HashTCopy)
unsigned int initialBucketCount = 10;
};
在我的源文件中,我这样定义函数并在我的复制构造函数中使用它:
void HashT::HashTCopy(struct Node** h1, Node** h2, unsigned int sz)
{
...
}
HashT::HashT(const HashT& hm)
{
new_HashT = new Node* [hm.initialBucketCount];
HashTCopy(new_HashT, hm.HashTArray, hm.initialBucketCount)
}
当我尝试编译它时,我收到一条错误消息:out-of-line definition HashT::HashTCopy..." 和....note: type of 1st parameter of member declaration does not match definition. 'struct Node**' aka 'HashMap::Node** vs 'struct Node** aka HashMap::Node**'。编译器指向struct...'void HashTCopy(struct Node** h1,....)`。我似乎无法弄清楚问题所在。我的声明和定义匹配,那么这里有什么问题?谢谢
【问题讨论】:
-
显示全部您的代码,because this works fine for me
-
会的。在调用该函数的复制构造函数中添加。
-
为什么不定义实现使用
HashT::Node(而不是struct Node)?
标签: c++ struct declaration member definition