omi*_*kun 0 c++ hash templates resize vector
我试图创建一个模板对象的矢量矢量.当我尝试调整内部向量的大小时,错误发生,我无法做出错误消息的头部或尾部.我不知道从何处获取HashTable :: Item :: Item.有什么建议?
/usr/include/c++/4.4.6/bits/stl_vector.h(552):错误:没有构造函数的实例"HashTable :: Item :: Item [with Key = int,Value = Varvalue]"匹配参数列表调整大小(size_type __new_size,value_type __x = value_type())
Run Code Online (Sandbox Code Playgroud)detected during: instantiation of "void std::vector<_Tp, _Alloc>::resize(std::vector<_Tp, _Alloc>::size_type={size_t={unsigned long}}, std::vector<_Tp, _Alloc>::value_type) [with _Tp=HashTable<int, Varvalue>::Item, _Alloc=std::allocator<HashTable<int, Varvalue>::Item>]" at line 118 of "main.cc"
这是相关代码:
#define VECLEN 16
class Varvalue
{
public:
char data[32];
};
template
class HashTable
{
private:
class Item
{
public:
bool valid;
Key key;
Value value;
Item *next;
Item(const Key k, const Value v, Item *b = 0, bool val = true):
key(k), value(v), next(b), valid(val) {}
};
vector<vector<Item> > table;
int tableSize;
HashTable(const int s): tableSize(s)
{
table.resize(tableSize);
for(int i=0; i<table.size(); i++)
table[i].resize(VECLEN); // <<-- error line 118
}
Run Code Online (Sandbox Code Playgroud)
}
int main()
{
HashTable<int, Varvalue> htable(nkeys);
}
| 归档时间: |
|
| 查看次数: |
1267 次 |
| 最近记录: |