I'm trying to serialize a class with a non-default constructor and static const data members, so
I have to override boost::serialization::save_construct_data() and load_construct_data(). I am
getting a linking error:the static members referred to in save_construct_data() cannot be found
("undefined reference").
#include
#include
#include
// forward declarations
class A;
namespace boost { namespace serialization {
template<class Archive>
inline void save_construct_data(Archive &ar, const A *t, const unsigned int file_version);
} }
class A {
friend class boost::serialization::access;
// friend function (omitting load_construct_data() for brevity)
template<class Archive>
friend void save_construct_data(Archive &ar, const A *t, const unsigned int file_version);
public:
static const int var1 = 1;
static const int var2 = 2;
template<class Archive>
void serialize(Archive & ar, const unsigned int file_version)
{
// do nothing
};
}
// overridden Boost function
namespace boost { namespace serialization {
template<class Archive>
inline void save_construct_data(
Archive &ar, const A *t, const unsigned int file_version)
{
// link errors happen at both of these two lines ("undefined reference" of var1, var2).
ar << boost::serialization::make_nvp("var1", ::A::var1);
ar << boost::serialization::make_nvp("var2", t->var2);
};
}} // namespace…
This puzzles me since I thought that static members have external linkage. This question seems
to be more about namespaces than it is about Boost::Serialization, but I post here because
some Serialization user must have run into it.
Thanks,
Kurt