未声明的标识符和类型"int"从 main 调用类时出现意外错误
Undeclared identifier and type 'int' unexpected error when calling a class from main
大家好,所以我正在为我的班级制作C 的哈希计划。我正在使用模板t类用于我的标题文件,当我尝试从MAIN调用类构造函数时,它会给我一个未申报的标识符,并键入" INT"意外错误。这是我的hashtable.h文件:
#pragma once
#include "Record.h"
#define MAXHASH 1000
#ifndef HASHTABLE_H
#define HASHTABLE_H
using namespace std;
template <class T> class HashTable
{
public:
HashTable();
~HashTable();
bool insert(int, T, int&);
bool remove(int);
bool find(int, T&);
float alpha();
private:
int key;
T value;
};
#endif
这是我的主要:
#include "HashTable.h"
#include "stdafx.h"
#include <string>
#include <iostream>
using namespace std;
int main()
{
HashTable<int> *test = new HashTable<int>();
return 0;
}
这也是.cpp文件中的构造函数:
#pragma once
#include "stdafx.h"
#include "HashTable.h"
#include "Record.h"
#define HASHTABLE_CPP
#ifndef HASTABLE_CPP
template <class T>
HashTable<T>::HashTable()
{
Record hashArray = new Record[MAXHASH];
for (int i = 0; i < MAXHASH; i++)
{
hashArray[i]->key = 0;
hashArray[i]->value = NULL;
}
}
我遇到的具体错误是:
Error C2062 type 'int' unexpected identifier Error C2065 'HashTable': undeclared identifier
两个错误都指向主呼叫线。
这很困难,因为我无法测试我的程序,直到我可以将此测试哈希工作。有关如何解决此问题的任何输入都很棒!
如果使用预编译的标头,则必须是第一个指令。它实际上效果最好,因为VS期望它...我总是使用它。
相关文章:
- vscode下的Arduino代码出现意外编译错误
- 错误 C2760:语法错误:映射迭代器上意外的标记"标识符",预期的";"
- C++标头错误 C2238 意外标记";"
- C++ 编译错误:意外的类型名称"字符串":预期的表达式
- 在gcc中意外调用了Const重载.编译器错误或兼容性修复程序
- "错误 C0000:语法错误,令牌"<EOF>"处出现意外$end,并且不确定
- boost::p rogram_options 在指定意外的位置参数时不报告任何错误
- 从 C++ 调用 cURL 命令会返回意外的错误代码,如 1792 和 6656
- Qt5 C++中出现意外"Multiple definition"错误
- 排序程序的意外错误代码
- 在 c++ 中声明向量时出现意外错误
- 函数调用中出现意外编译错误 (C++)
- 使用相同的函数时意外收到"std::out_of_range"错误
- 在第三个 pary 函数中使用矢量引用时出现意外错误
- 创建进程失败,意外错误
- 企业架构师错误:意外符号修复
- 在 Linux C++的两个线程之间使用管道的错误/意外行为
- Mex运行时错误:意外的标准表达式
- Cmake 奇怪的错误:语法错误意外的令牌 ('
- Cuda错误:意外启动失败