【发布时间】:2013-08-08 07:21:38
【问题描述】:
我正在写一个哈希类:
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]; // <--
};
由于 insert() 在插入新对时需要检查 table[i] 是否为空,所以我需要在启动时将表中的所有指针设置为 NULL。
我的问题是,这个指针数组table_会自动初始化为零,还是我应该在构造函数中手动使用循环将数组设置为零?
【问题讨论】:
-
hashnode* table_[SIZE]{}; -
我希望您只是将其作为练习,因为 C++ 在
std::unordered_map中已经有一个哈希映射。 -
@JoachimPileborg 遗憾的是我的项目中没有 C++11 和提升。
-
@Deqing,是的,没有答案也可以,但这是最干净的一个。
-
@BЈовић, Are you sure?
标签: c++ initialization member c++03