Question

I am not using any templates, and it isn't a static class or function so I have absolutely no idea why it is throwing me a LNK2001 error when it is defined. Here is the full error:

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)

My MapGenerator class;

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;


};

And the accompanying definition in the .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;
}

I am calling the function like this,

std::string test(node->FirstChild("data")->Value());
data = Decode(test);

I'm not sure why it is complaining, when everything looks appropriate. On a side note, I've tried making the function take a const char* const instead of an std::string, since that is what Value() returns but I still receive the LNK2001 error. Any ideas?

Was it helpful?

Solution

 std::vector<int> Decode(std::string data)

should have the classname with :: scope resolution operator.

 std::vector<int> MapGenerator::Decode(std::string data)
                  //^^^^^

Since it is a member function of MapGenerator class.

OTHER TIPS

You should do :

std::vector<int> MapGenerator::Decode(std::string data)
{
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top