Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/visual-studio-2010/4.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C++ visualc&x2B+;链接器错误2019_C++_Visual Studio 2010_Linker - Fatal编程技术网

C++ visualc&x2B+;链接器错误2019

C++ visualc&x2B+;链接器错误2019,c++,visual-studio-2010,linker,C++,Visual Studio 2010,Linker,我试图在一些文件中包含一个简单的哈希表类,并带有一个头类。但每当我尝试编译时,都会出现如下错误: LNK2019:未解析的外部符号“public:u thiscall哈希表::~HashTable(void)”(??1HashTable@@QAE@XZ)在函数_main中引用” 我使用的是Visual Studio 2010。我知道这意味着它在任何源文件中都找不到函数定义。但我已在与调用它的文件位于同一目录的文件中定义了它们。除非设置了某些链接器选项,否则Visual Studio可能不会在当前

我试图在一些文件中包含一个简单的哈希表类,并带有一个头类。但每当我尝试编译时,都会出现如下错误:

LNK2019:未解析的外部符号“public:u thiscall哈希表::~HashTable(void)”(??1HashTable@@QAE@XZ)在函数_main中引用”

我使用的是Visual Studio 2010。我知道这意味着它在任何源文件中都找不到函数定义。但我已在与调用它的文件位于同一目录的文件中定义了它们。除非设置了某些链接器选项,否则Visual Studio可能不会在当前目录中查找

以下是源代码:

//HashTable.h
#ifndef HASH_H
#define HASH_H

class HashTable {

public:
    HashTable();
    ~HashTable();
    void AddPair(char* address, int value);
    //Self explanatory
    int GetValue(char* address);
    //Also self-explanatory. If the value doesn't exist it throws "No such address"

};

#endif



//HashTable.cpp
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;
    };

};
//HashTable.h
#ifndefhash_H
#定义哈希值
类哈希表{
公众:
哈希表();
~HashTable();
void AddPair(字符*地址,int值);
//不言自明
int GetValue(字符*地址);
//也不言自明。如果该值不存在,则抛出“无此类地址”
};
#恩迪夫
//HashTable.cpp
类哈希表{
受保护的:
int高值;
字符**地址表;
int*表格;
公众:
哈希表(){
高值=0;
}
~HashTable(){
删除地址表;
删除表格;
}
void AddPair(字符*地址,int值){
AddressTable[高值]=地址;
表[高值]=值;
高值+=1;
}
int GetValue(字符*地址){

对于(int i=0;i否),您尚未创建。您创建了一个新的

定义方法的正确方法是:

//HashTable.cpp

#include "HashTable.h"
HashTable::HashTable(){
    HighValue = 0;
}
HashTable::~HashTable(){
    delete AddressTable;
    delete Table;
}
void HashTable::AddPair(char* address, int value){
    AddressTable[HighValue] = address;
    Table[HighValue] = value;
    HighValue += 1;
}
int HashTable::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;
};
//HashTable.cpp
#包括“HashTable.h”
HashTable::HashTable(){
高值=0;
}
哈希表::~HashTable(){
删除地址表;
删除表格;
}
void HashTable::AddPair(字符*地址,int值){
AddressTable[高值]=地址;
表[高值]=值;
高值+=1;
}
int哈希表::GetValue(字符*地址){

对于(int i=0;iAh.因此,在定义函数时,我应该使用HashTable::function()?并且我会在头文件中包含任何私有变量,对吗?@user1296991是的,您在类定义中声明数据成员。类定义是头文件中的一部分:
class HashTable{……};