|
Boost Users : |
From: Cheok Yan Cheng (yccheok_at_[hidden])
Date: 2006-08-10 05:06:17
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_at_Vtext_oarchive_at_archive@boost@@@cat@@ABEXAAVtext_oarchive_at_archive@boost@@I_at_Z)
referenced in function "public: static void __cdecl
boost::serialization::access::member_save<class
boost::archive::text_oarchive,class cat const >(class
boost::archive::text_oarchive &,class cat const
&,unsigned int)"
(??$member_save_at_Vtext_oarchive_at_archive@boost@@$$CBVcat@@@access_at_serialization@boost@@SAXAAVtext_oarchive_at_archive@2_at_ABVcat@@I_at_Z)
------
cat.h
------
#ifndef CAT_H
#define CAT_H
#include <boost/archive/text_oarchive.hpp>
#include <boost/archive/text_iarchive.hpp>
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 <boost/archive/text_oarchive.hpp>
#include <boost/archive/text_iarchive.hpp>
#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 <boost/archive/text_oarchive.hpp>
#include <boost/archive/text_iarchive.hpp>
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
Boost-users list run by williamkempf at hotmail.com, kalb at libertysoft.com, bjorn.karlsson at readsoft.com, gregod at cs.rpi.edu, wekempf at cox.net