我正在关注哈希表实现教程并遇到了这个:
class HashTable {
private:
static const int hashGroups = 10;
std::list<std::pair<int,std::string>> table[hashGroups];
Run Code Online (Sandbox Code Playgroud)
bool HashTable::isEmpty() const {
int sum{};
for(int i{}; i < hashGroups; i++) {
sum += table[i].size();
}
if(!sum) {
return true;
}
return false;
}
Run Code Online (Sandbox Code Playgroud)
在 isEmpty() 成员函数中,为什么 table[i].size() 有效?在我的解释中,table 是一个对的列表,因此,table[i] 应该在索引 [i] 处返回一个对。但是,std::pair 中没有成员函数 size()。
归档时间: |
|
查看次数: |
92 次 |
最近记录: |