I am learning to use boost to serilaize some of my classes in C++.
I have a struct in an interface. I use the boost serilaize function to serialize this struct like this.
Interface.h
struct X {
const Long rate;
}
template <class Archive>
void serialize(Archive& ar, uint32 version)
{
ar & this->rate;
}
BOOST_CLASS_EXPORT(X);
Now this header will be used by my main class. Let say main.cpp, Header for this main class has
Main.h
#include "Interface.h"
class Main {
// some stuff
template <class Archive>
void serialize(Archive& ar, uint32 version);
X x;
friend class boost::serialization::access;
};
template <class Archive>
void
Main::serialize(Archive& ar, uint32 version)
{
ar & x;
}
BOOST_CLASS_EXPORT_KEY(Main);
Main.cpp
BOOST_CLASS_EXPORT_IMPLEMENT(Main);
When I try to compile this code I get the following error:
C:\Users\boost1470_win64_vc90sp1\include\boost/archive/detail/check.hpp(162) : error C2027: use of undefined type 'boost::STATIC_ASSERTION_FAILURE' with [ x=false ]
C:\Users\boost1470_win64_vc90sp1\include\boost/archive/detail/iserializer.hpp(577) : see reference to function template instantiation 'void boost::archive::detail::check_const_loading(void)' being compiled with [ T=const Long
C:\Users\interfaces/Interface.h(12) : see reference to function template instantiation 'Archive &boost::archive::detail::interface_iarchive::operator &(T &)' being compiled with [ Archive=boost::archive::text_iarchive, T=const Long ]
C:\Users\interfaces/Interface.h(17) : see reference to class template instantiation 'boost::archive::detail::extra_detail::guid_initializer' being compiled with [ T=X ]
Any idea what is going wrong. I am new to boost and figuring out how this works.
Note: If I use an int in the struct instead of long I do not see the boost::STATIC_ASSERTION_FAILURE error.
rate
is const. How is deserialization going to set it to the right value? – Alan Stokesconst_cast
might help). – alfC