I am using VC++ 2003. I realize that when I provide
the code defination for save and load on cpp file, the
following error will occur:
animal error LNK2019: unresolved external symbol
"private: void __thiscall cat::save<class
boost::archive::text_oarchive>(class
boost::archive::text_oarchive &,unsigned int)const "
(??$save@Vtext_oarchive@archive@boost@@@cat@@ABEXAAVtext_oarchive@archive@boost@@I@Z)
referenced in function "public: static void __cdecl
boost::serialization::access::member_save(class
boost::archive::text_oarchive &,class cat const
&,unsigned int)"
(??$member_save@Vtext_oarchive@archive@boost@@$$CBVcat@@@access@serialization@boost@@SAXAAVtext_oarchive@archive@2@ABVcat@@I@Z)
------
cat.h
------
#ifndef CAT_H
#define CAT_H
#include
#include
class cat
{
private:
friend class boost::serialization::access;
template<class Archive>
void save(Archive & ar, const unsigned int
version) const;
template<class Archive>
void load(Archive & ar, const unsigned int
version);
BOOST_SERIALIZATION_SPLIT_MEMBER()
};
#endif
-------
cat.cpp
-------
#include "cat.h"
template<class Archive>
void cat::save(Archive & ar, const unsigned int
version) const
{
}
template<class Archive>
void cat::load(Archive & ar, const unsigned int
version)
{
}
--------
main.cpp
--------
#include <iostream>
#include <cassert>
#include <string>
#include <sstream>
#include <fstream>
#include
#include
#include "cat.h"
int main()
{
const cat c;
// make an archive
std::ofstream ofs("test");
boost::archive::text_oarchive oa(ofs);
oa << c;
}
However, if I remove cat.cpp file during compilation
and having the code defination at header file as
follow, the code compiled with no problem. May I know
how I can put my serialization code at cpp file
instead of header file? Thank you very much!
The reason I want to do so is that I need to perform
class forwarding in certain classes. Due to the reason
class forwarding unable to provide a full information
of a class at header level, serialization code can
only be written in cpp file level.
------
cat.h
------
#ifndef CAT_H
#define CAT_H
#include
#include
class cat
{
private:
friend class boost::serialization::access;
template<class Archive>
void save(Archive & ar, const unsigned int
version) const{}
template<class Archive>
void load(Archive & ar, const unsigned int
version) {}
BOOST_SERIALIZATION_SPLIT_MEMBER()
};
#endif
__________________________________________________
Do You Yahoo!?
Tired of spam? Yahoo! Mail has the best spam protection around
http://mail.yahoo.com