我没有使用任何模板,它不是静态类或函数,所以我完全不知道为什么它在定义时会抛出 LNK2001 错误。这是完整的错误:
1>mapgenerator.obj : error LNK2019: unresolved external symbol "private: class std::vector<int,class std::allocator<int> > __thiscall MapGenerator::Decode(class std::basic_string<char,struct std::char_traits<char>,class std::allocator<char> >)" (?Decode@MapGenerator@@AAE?AV?$vector@HV?$allocator@H@std@@@std@@V?$basic_string@DU?$char_traits@D@std@@V?$allocator@D@2@@3@@Z) referenced in function "private: void __thiscall MapGenerator::GenerateTileLayer(class TiXmlNode *)" (?GenerateTileLayer@MapGenerator@@AAEXPAVTiXmlNode@@@Z)
我的 MapGenerator 类;
class MapGenerator
{
public:
//Constructor and destructor
MapGenerator(std::string tmxfile) : doc(tmxfile.c_str()) { Load(); }
~MapGenerator();
//Loads in a new TMX file
void Load();
//Returns a map
void GetMap();
//Reads the TMX document
void Read();
private:
//The TMX document
TiXmlDocument doc;
//Generates a tile layer
void GenerateTileLayer(TiXmlNode* node);
//Generates a tileset
void GenerateTileset(TiXmlNode* node);
//Generates an Object Layer
void GenerateObjectLayer(TiXmlNode* node);
//Generates a Map Object(Goes in the object layer)
void GenerateObject(TiXmlNode* node);
//Decodes the data
std::vector<int> Decode(std::string data);
bool loadOkay;
};
以及 .cpp 中的随附定义,
std::vector<int> Decode(std::string data)
{
//Represents the layer data
std::vector<int> layerdata;
//Decodes the data
data = base64_decode(data);
//Shift bits
for(unsigned int i = 0; i < data.size(); i+=4)
{
const int gid = data[i] |
data[i + 1] << 8 |
data[i + 2] << 16 |
data[i + 3] << 24;
//Add the resulting integer to the layer data vector
layerdata.push_back(gid);
}
//Return the layer data vector
return layerdata;
}
我这样调用函数,
std::string test(node->FirstChild("data")->Value());
data = Decode(test);
当一切看起来都合适时,我不确定它为什么会抱怨。附带说明一下,我尝试让函数采用 const char* const 而不是 std::string,因为这是 Value() 返回的,但我仍然收到 LNK2001 错误。有任何想法吗?