【发布时间】:2011-12-01 09:01:32
【问题描述】:
我有一个我正在尝试制作的HashTable 课程的大纲。我从 Visual Studio 得到 3 个错误输出,但在这里看不到问题。我对 C++ 中的 OO 相当陌生,所以这可能是我错过的东西。它声称我的向量数组存在问题。错误是:
error C2143: syntax error : missing ';' before '<' line 10
error C2238: unexpected token(s) preceding ';' line 10
error C4430: missing type specifier - int assumed. Note: C++ does not support default-int line 10
这是我的完整课程,现在很空:
#include <iostream>
#include <vector>
#include "stdafx.h"
using namespace std;
class HashTable
{
private:
const static int buckets = 100;
vector<int> hashTable[buckets]; //Internal storage
int hash(int toHash); //Performs hash function
public:
HashTable(); //Constructor
HashTable(int s); //Constructor
~HashTable(); //Destructor
void add(int toAdd); //Adds an element to the HashTable
void remove(int toDelete); //Deletes an element from the HashTable
bool search(int toSearch); //Returns true if element in HashTable, false otherwise
int getSize(); //Returns size of HashTable
void print(); //Prints current state of the hashtable
//TODO more methods...?
};
//Definitions...
HashTable::HashTable()
{
}
HashTable::~HashTable()
{
//cout << "Destroyed" << endl;
}
void HashTable::add(int toAdd)
{
//elements[hash(toAdd)] = toAdd;
}
void HashTable::remove(int toDelete)
{
}
bool HashTable::search(int toSearch)
{
}
int HashTable::getSize()
{
//return size;
}
void HashTable::print()
{
}
int main()
{
return 0;
}
【问题讨论】:
-
你为什么不用
vector <vector <int> > hashTable; -
只在类体内声明桶,在类声明外定义
-
如果删除
#include "stdafx.h"会发生什么?在 VC++ 2010 中,我得到的唯一错误与未返回声明值的函数有关。 -
@e-MEE:我相信它是一个向量数组