Deq*_*ing 0 c++ initialization member c++03
我正在写一个哈希类:
struct hashmap {
void insert(const char* key, const char* value);
char* search(const char* key);
private:
unsigned int hash(const char* s);
hashnode* table_[SIZE]; // <--
};
Run Code Online (Sandbox Code Playgroud)
因为insert()需要在插入新对时检查table [i]是否为空,所以我需要在启动时将表中的所有指针设置为NULL.
我的问题是,这个指针数组table_会自动初始化为零,还是我应该手动使用循环在构造函数中将数组设置为零?
该table_阵列将未初始化在当前的设计,就像如果你说int n;.但是,您可以在构造函数中对数组进行值初始化(从而对每个成员进行零初始化):
struct hash_map
{
hash_map()
: table_()
{
}
// ...
};
Run Code Online (Sandbox Code Playgroud)