我没有使用任何模板,它不是静态类或函数,所以我完全不知道为什么它定义时会给我一个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)
Run Code Online (Sandbox Code Playgroud)
我的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;
};
Run Code Online (Sandbox Code Playgroud)
以及.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;
}
Run Code Online (Sandbox Code Playgroud)
我正在调用这样的函数,
std::string test(node->FirstChild("data")->Value());
data = Decode(test);
Run Code Online (Sandbox Code Playgroud)
当一切看起来合适时,我不确定它为什么抱怨.另外,我已经尝试使函数采用const char*const而不是std :: string,因为这是Value()返回但我仍然收到LNK2001错误.有任何想法吗?
std::vector<int> Decode(std::string data)
Run Code Online (Sandbox Code Playgroud)
应该具有带有::范围解析运算符的classname .
std::vector<int> MapGenerator::Decode(std::string data)
//^^^^^
Run Code Online (Sandbox Code Playgroud)
因为它是MapGenerator类的成员函数.
| 归档时间: |
|
| 查看次数: |
2268 次 |
| 最近记录: |