我正在嘗試創建一個HashTable
類的輪廓。我從Visual Studio中獲得了3個錯誤輸出,但我在這裏看不到問題。我在C++中對OO相當陌生,所以這可能是我錯過的東西。它聲稱我的向量數組有問題。的錯誤是:語法錯誤:OO中的向量數組C++
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> hashTable;' –
只是在類體內聲明桶並在類聲明外定義它 –
如果刪除'#include「stdafx.h」'會發生什麼?在VC++ 2010中,我得到的唯一錯誤與函數沒有返回聲明的值有關。 –