I am trying to write non-intrusive boost :: serialization routines for a nested class with a private member. Unfortunately, I cannot convince g ++ that the serialization procedure is a friend of the inner class. G ++ seems to require a direct declaration of the serialization procedure, which in turn will require a direct declaration of the nested class, which in turn cannot be executed in C ++. Am I missing something or is it just not possible? clang ++, by contrast, does not require a direct declaration and has no problems with the code below. The following code illustrates the problem:
#include <boost/archive/text_oarchive.hpp>
class Outer;
namespace boost
{
namespace serialization
{
template <class Archive>
void serialize(Archive &ar, Outer& outer, const unsigned int version);
}
}
class Outer
{
class Inner
{
int member_{42};
template <class Archive>
friend void boost::serialization::serialize(Archive &ar, Outer::Inner &inner, const unsigned int version);
};
Inner inner_;
template <class Archive>
friend void boost::serialization::serialize(Archive &ar, Outer &outer, const unsigned int version);
template <class Archive>
friend void boost::serialization::serialize(Archive &ar, Inner &inner, const unsigned int version);
};
namespace boost
{
namespace serialization
{
template <class Archive>
void serialize(Archive &ar, Outer& outer, const unsigned int version)
{
ar & outer.inner_;
}
template <class Archive>
void serialize(Archive &ar, Outer::Inner& inner, const unsigned int version)
{
ar & inner.member_;
}
}
}
int main()
{
Outer outer;
boost::archive::text_oarchive(std::cout) << outer;
}
-std=c++11 -lboost_serialization. g++ , member_ , . g++ ?