<分区>
当我尝试编译我的 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);
}