未声明的标识符和类型';int';从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

未声明的标识符和类型';int';从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,c++,templates,hash,C++,Templates,Hash,这两个错误都指向main中的呼叫线路 这很难,因为我无法测试我的程序,直到我可以得到这个测试哈希工作。关于如何解决这个问题的任何意见都将非常棒 如果使用预编译的头,则旧的Microsoft应用程序文件扩展名接口“stdafx.h”必须是列出的第一个指令。它实际上工作得最好,因为VS期望它…我总是使用它。使用typename T还不是一个副本,但一旦你得到它进行编译,你就会遇到它除非必须,否则不要更新哈希表测试很可能会执行您想要的操作。还要注意Record hashArray=new Record

这两个错误都指向main中的呼叫线路


这很难,因为我无法测试我的程序,直到我可以得到这个测试哈希工作。关于如何解决这个问题的任何意见都将非常棒

如果使用预编译的头,则旧的Microsoft应用程序文件扩展名接口“stdafx.h”必须是列出的第一个指令。它实际上工作得最好,因为VS期望它…我总是使用它。

使用
typename T
还不是一个副本,但一旦你得到它进行编译,你就会遇到它除非必须,否则不要更新<代码>哈希表测试很可能会执行您想要的操作。还要注意
Record hashArray=new Record[MAXHASH]
hashArray
是一个局部变量,因此一旦函数退出,您将无法知道分配的存储在何处。考虑让它成为一个成员变量,和以前一样,避免<代码>新< /代码> ING。当你在VisualStudio中获得神秘编译错误时,首先要做的就是删除<代码>包含“STDAFX.H”;这是微软的东西,应该只是一个编译时优化,但它经常把事情搞砸。(而且,如果使用它,它应该是第一个
#include
指令)我觉得很愚蠢,但这是因为#include“stdafx.h”不是第一个。哈哈,太谢谢你们了!
#include "HashTable.h"
#include "stdafx.h"
#include <string>
#include <iostream>
using namespace std;

int main()
{
    HashTable<int> *test = new HashTable<int>();
    return 0;
}
#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