未声明的标识符和类型"int"从 main 调用类时出现意外错误

Undeclared identifier and type 'int' unexpected error when calling a class from main

本文关键字:错误 意外 调用 标识符 类型 未声明 int main      更新时间:2023-10-16

大家好,所以我正在为我的班级制作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期望它...我总是使用它。