c++ - LNK2019 Unresolved external symbol 错误

标签 c++ lnk2019 unresolved-external

<分区>

当我尝试编译我的 VS2012 项目时出现以下错误:

错误 LNK2019:未解析的外部符号“public: int __thiscall map::GetBlockRef(int,int)”(?GetBlockRef@map@@QAEHHH@Z) 在函数“public: void __thiscall map::LoadLevel(int)”中引用"(?LoadLevel@map@@QAEXH@Z)

错误 LNK1120:1 个 Unresolved external 问题

我已经检查了多个站点是否存在类似问题,但没有找到任何问题。问题是在 void map::LoadLevel(int) 中调用了 int map::GetBlockRef(int, int)

为什么我不能调用 GetBlockRef()?

map .h

#ifndef MAP_H
#define MAP_H

#include <windows.h>
#include <vector>
#include "Block.h"

using namespace std;

class map
{
    public:
        map();
        int GetGridCoord(int);
        int GetBlockRef(int, int); //Declared correctly
        void LoadLevel(int);

        vector<block>blocks;
        vector<int>blockRef;
};

#endif

map .cpp

#include "Map.h"

map::map()
{
    for(int i = 0; i < 196; i++)
    {
        blockRef.push_back(-1);
    }
}

int GetGridCoord(int v)
{
    return (v / 48) - 1;
}

int GetBlockRef(int x, int y) //Defined correctly
{
    x = GetGridCoord(x);
    y = GetGridCoord(y);

    int index = x + (14 * y);

    return index;
}

void map::LoadLevel(int level)
{
    int index;
    block tmpBlock;

    tmpBlock.InitBlockData(144, 144, "rock");
    index = GetBlockRef(tmpBlock.xPos, tmpBlock.yPos);  //THIS IS CAUSING ERRORS!!
    blockRef[index] = 0;
    blocks.push_back(tmpBlock);
}

最佳答案

//正确定义 不是真的。

int GetBlockRef(int x, int y)int map::GetBlockRef(int x, int y)

关于c++ - LNK2019 Unresolved external symbol 错误,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/22114141/

相关文章:

c++ - 链接器 2001 错误和成员变量的未定义标识符

opencv - 使用OpenCV将多维矩阵初始化为多维矩阵会产生链接错误

C++0x 没有信号量?如何同步线程?

c++ - 为什么 cv::Mat 的 RAM 和硬盘大小总是有 4.5 倍的差异?

c++ - 未解析的外部符号 LNK2019 混淆

c++ - LNK2019: 单例 Unresolved 错误

c++ - 为什么在使用快速数学时 GCC 或 Clang 不优化 1 条指令的倒数

c++ - C++ 枚举访问语义背后的基本原理

c++ - 无法链接 GLFW C++;添加了 .dll、.h、.lib,但仍然获取 LNK2019

c++ - 未解析的外部符号(再次)