[英]Syntax error: Array of Vectors in OO C++
我有一个我正在尝试制作的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;
}
这里的C ++是有效的(一旦填写空函数)。 问题在于Visual C ++如何使用预编译头。 当您使用预编译头文件(默认设置)时,Visual C ++编译器期望每个实现文件的第一行是#include "stdafx.h"
,并且不会编译之前出现的任何内容。
这意味着忽略了代码中<vector>
的包含,因此编译vector<int>
会导致错误。
如果将#include "stdafx.h"
移到顶部,则应编译。 或者,您可以在项目设置中禁用预编译的标头。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.