我正在尝试用 C++ 编写一个类,但每当我尝试编译时,它都会因以下错误而失败:
“ fatal error C1004:发现意外的文件结尾”
我正在使用 VS2010。微软的文档(http://msdn.microsoft.com/en-us/library/4exw7xyc(v=vs.80).aspx)说这个错误是由于缺少右括号、分号等引起的。但我可以看到从代码突出显示所有大括号都匹配,我相信如果您缺少分号,您会收到通知。
class HashTable {
protected:
int HighValue;
char** AddressTable;
int* Table;
public:
HashTable(){
HighValue = 0;
}
~HashTable(){
delete AddressTable;
delete Table;
}
void AddPair(char* address, int value){
AddressTable[HighValue] = address;
Table[HighValue] = value;
HighValue += 1;
}
int GetValue(char* address){
for (int i = 0; i<HighValue; i++){
if (AddressTable[HighValue] == address) {
return Table[HighValue];
}
}
//If the value doesn't exist throw an exception to the calling program
throw 1;
};
}
最佳答案
类定义必须以分号结尾:
class HashTable {
// ...
};
关于C++ 错误代码 C1004,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/9900470/