I'm new to c++, and found the boost library just recently. In my small program I'm using to learn c++ (I'm using MSVC 2015), I want to use boost serialisation to save/load my player class. I have Implemented the required functions in my class like so:
Player.h
class Player
{
public:
Player();
private:
friend class boost::serialization::access;
template<class Archive>
void serialize(Archive & ar, const unsigned int version);
int race; //For now im only attempting to serialize one variable to make it as simple as possible.
};
Player.cpp
using namespace std;
Player::Player()
{
race = -1; //Default value for race.
}
//Serialisation:
template<class Archive>
void Player::serialize(Archive & ar, const unsigned int version) {
ar & race;
}
...Other unnecessary functions not listed
Main.cpp
void savePlayer() { //Called when player is to be saved.
string filename;
filename = p.getName() + "_" + getTime();
{
std::ofstream ofs(filename);
boost::archive::binary_oarchive oa(ofs);
oa << p; //Removing this line stops the error from occouring for some reason.
}
}
On compilation i get the following error:
Main.obj : error LNK2019: unresolved external symbol "private: void __thiscall Player::serialize<class boost::archive::binary_oarchive>(class boost::archive::binary_oarchive &,unsigned int)" (??$serialize@Vbinary_oarchive@archive@boost@@@Player@@AAEXAAVbinary_oarchive@archive@boost@@I@Z) referenced in function "public: static void __cdecl boost::serialization::access::serialize<class boost::archive::binary_oarchive,class Player>(class boost::archive::binary_oarchive &,class Player &,unsigned int)" (??$serialize@Vbinary_oarchive@archive@boost@@VPlayer@@@access@serialization@boost@@SAXAAVbinary_oarchive@archive@2@AAVPlayer@@I@Z)
1>E:\Users\James\Documents\Programming\Visual Studio 2015\Projects\Text Rpg v1.0\Debug\Text Rpg v1.0.exe : fatal error LNK1120: 1 unresolved externals
I've browsed online for hours looking for a solution, the closest i could find was this: http://boost.2283326.n4.nabble.com/Help-with-Visual-Studio-settings-for-Boost-Serialization-td3072458.html It would be really nice to find a solution to this problem as there are no apparent solutions online.
Thanks in advanced - Yepadee.