在堆上实例化对象

时间:2011-03-28 02:09:41

标签: c++ object compiler-errors heap

我收到错误:

hashing.cpp: In function ‘int main(int, char**)’:
hashing.cpp:96: error: expected type-specifier before ‘Linked_HashTable’
hashing.cpp:96: error: cannot convert ‘int*’ to ‘LinkedList_HashTable*’ in initialization
hashing.cpp:96: error: expected ‘,’ or ‘;’ before ‘Linked_HashTable’

编译我的代码时。我想我错过了很容易理解的东西。

给我错误的代码是:

Array_HashTable *linear_div_hash = new Array_HashTable(sizeDiv);
LinkedList_HashTable *chain_div_hash = new Linked_HashTable(sizeDiv);
Array_HashTable *doubleHash = new Array_HashTable(sizeDiv);

Array_HashTableLinkedList_HashTable()的构造函数取sizeDiv之类的整数。非常感谢任何帮助。

谢谢!

3 个答案:

答案 0 :(得分:1)

应该

LinkedList_HashTable *chain_div_hash = new Linked_HashTable(sizeDiv); 

LinkedList_HashTable *chain_div_hash = new LinkedList_HashTable(sizeDiv);

? (请注意代码中缺少的List。)

答案 1 :(得分:0)

LinkedList_HashTable *chain_div_hash = new LinkedList_HashTable(sizeDiv);

也许您输入了Linked_HashTable但是LinkedList_HashTable

答案 2 :(得分:0)

看起来您在LinkedList_HashTable行上将Linked_HashTable错误键入为LinkedList_HashTable *chain_div_hash = new Linked_HashTable(sizeDiv);,导致编译器认为Linked_HashTable(sizeDiv);是对隐式声明的函数的函数调用,该函数返回{ {1}}。