Strange compile error with Boost.Serialization

Hello all, when I compile the code below (with MSVC 7.1), I get an error telling me that "'serialize' : is not a member of 'std::vector<_Ty>'". I will post the exact error message below the code. The strange thing about this is that when I change the #define TEST line to #define TEST 1 (or 2 or 3), it compiles ok [1 means that only the iarchive is used, 2 that the oarchive is used, and 3 that a 'B' object is serialized instead of an 'A' object]. Is there anything wrong with the code? Thanks and best regards, Klaus <code> #include <boost/serialization/vector.hpp> #include <boost/serialization/nvp.hpp> #include <boost/archive/binary_oarchive.hpp> #include <boost/archive/binary_iarchive.hpp> #include <sstream> #define TEST 0 // Change this to 1, 2, or 3 struct C { int m_; template <class Archive> void serialize(Archive& ar, size_t i) { ar & BOOST_SERIALIZATION_NVP(this->m_); } }; struct B { std::vector<C> m_; template <class Archive> void serialize(Archive& ar, size_t i) { ar & BOOST_SERIALIZATION_NVP(this->m_); } }; struct A { B m_; template <class Archive> void serialize(Archive& ar, size_t i) { ar & BOOST_SERIALIZATION_NVP(this->m_); } }; void save() { #if TEST != 3 A object; #else B object; #endif std::stringstream str; boost::archive::binary_oarchive ar(str); #if TEST != 1 ar << BOOST_SERIALIZATION_NVP(object); #endif } void load() { #if TEST != 3 A object; #else B object; #endif std::stringstream str; boost::archive::binary_iarchive ar(str); #if TEST != 2 ar >> BOOST_SERIALIZATION_NVP(object); #endif } int main(int, char**) { return 0; } </code> <errormessage> ../../Libraries\Boost\include\boost-1_32\boost\serialization\access.hpp(106) : error C2039: 'serialize' : is not a member of 'std::vector<_Ty>' with [ _Ty=C ] ../../Libraries\Boost\include\boost-1_32\boost\serialization\serialization.hpp(78) : see reference to function template instantiation 'void boost::serialization::access::serialize<Archive,T>(Archive &,T &,const unsigned int)' being compiled with [ Archive=boost::archive::binary_iarchive, T=std::vector<C> ] ../../Libraries\Boost\include\boost-1_32\boost\serialization\serialization.hpp(121) : see reference to function template instantiation 'void boost::serialization::serialize<Archive,T>(Archive &,T &,const unsigned int)' being compiled with [ Archive=boost::archive::binary_iarchive, T=std::vector<C> ] ../../Libraries\Boost\include\boost-1_32\boost\archive\detail\iserializer.hpp(159) : see reference to function template instantiation 'void boost::serialization::serialize_adl<Archive,T>(Archive &,T &,const unsigned int)' being compiled with [ Archive=boost::archive::binary_iarchive, T=std::vector<C> ] ../../Libraries\Boost\include\boost-1_32\boost\archive\detail\iserializer.hpp(109) : while compiling class-template member function 'void boost::archive::detail::iserializer<Archive,T>::load_object_data(boost::archive::detail::basic_iarchive &,void *,const unsigned int) const' with [ Archive=boost::archive::binary_iarchive, T=std::vector<C> ] ../../Libraries\Boost\include\boost-1_32\boost\archive\detail\iserializer.hpp(328) : see reference to class template instantiation 'boost::archive::detail::iserializer<Archive,T>' being compiled with [ Archive=boost::archive::binary_iarchive, T=std::vector<C> ] ../../Libraries\Boost\include\boost-1_32\boost\archive\detail\iserializer.hpp(326) : while compiling class-template member function 'void boost::archive::detail::load_non_pointer_type<Archive,T>::load::invoke(Archive &,T &)' with [ Archive=boost::archive::binary_iarchive, T=std::vector<C> ] ../../Libraries\Boost\include\boost-1_32\boost\archive\detail\iserializer.hpp(366) : see reference to class template instantiation 'boost::archive::detail::load_non_pointer_type<Archive,T>::load' being compiled with [ Archive=boost::archive::binary_iarchive, T=std::vector<C> ] ../../Libraries\Boost\include\boost-1_32\boost\archive\detail\iserializer.hpp(331) : while compiling class-template member function 'void boost::archive::detail::load_non_pointer_type<Archive,T>::invoke(Archive &,T &)' with [ Archive=boost::archive::binary_iarchive, T=std::vector<C> ] ../../Libraries\Boost\include\boost-1_32\boost\archive\detail\iserializer.hpp(529) : see reference to class template instantiation 'boost::archive::detail::load_non_pointer_type<Archive,T>' being compiled with [ Archive=boost::archive::binary_iarchive, T=std::vector<C> ] ../../Libraries\Boost\include\boost-1_32\boost\archive\basic_binary_iarchive.hpp(66) : see reference to function template instantiation 'void boost::archive::load<Archive,T>(Archive &,T &)' being compiled with [ Archive=boost::archive::binary_iarchive, T=std::vector<C> ] ../../Libraries\Boost\include\boost-1_32\boost\archive\binary_iarchive.hpp(45) : see reference to function template instantiation 'void boost::archive::basic_binary_iarchive<Archive>::load_override<T>(T &,int)' being compiled with [ Archive=boost::archive::binary_iarchive, T=std::vector<C> ] ../../Libraries\Boost\include\boost-1_32\boost\archive\detail\interface_iarchive.hpp(92) : see reference to function template instantiation 'void boost::archive::binary_iarchive_impl<Archive>::load_override<T>(T &,int)' being compiled with [ Archive=boost::archive::binary_iarchive, T=std::vector<C> ] ../../Libraries\Boost\include\boost-1_32\boost\serialization\nvp.hpp(58) : see reference to function template instantiation 'Archive &boost::archive::detail::interface_iarchive<Archive>::operator &<T>(T &)' being compiled with [ Archive=boost::archive::binary_iarchive, T=std::vector<C> ] ../../Libraries\Boost\include\boost-1_32\boost\serialization\access.hpp(106) : see reference to function template instantiation 'void boost::serialization::nvp<T>::serialize<Archive>(Archive &,const unsigned int) const' being compiled with [ T=std::vector<C>, Archive=boost::archive::binary_iarchive ] ../../Libraries\Boost\include\boost-1_32\boost\serialization\serialization.hpp(78) : see reference to function template instantiation 'void boost::serialization::access::serialize<Archive,T>(Archive &,T &,const unsigned int)' being compiled with [ Archive=boost::archive::binary_iarchive, T=boost::serialization::nvp<std::vector<C>> ] ../../Libraries\Boost\include\boost-1_32\boost\serialization\serialization.hpp(121) : see reference to function template instantiation 'void boost::serialization::serialize<Archive,T>(Archive &,T &,const unsigned int)' being compiled with [ Archive=boost::archive::binary_iarchive, T=boost::serialization::nvp<std::vector<C>> ] ../../Libraries\Boost\include\boost-1_32\boost\archive\detail\iserializer.hpp(320) : see reference to function template instantiation 'void boost::serialization::serialize_adl<Archive,T>(Archive &,T &,const unsigned int)' being compiled with [ Archive=boost::archive::binary_iarchive, T=boost::serialization::nvp<std::vector<C>> ] ../../Libraries\Boost\include\boost-1_32\boost\archive\detail\iserializer.hpp(314) : while compiling class-template member function 'void boost::archive::detail::load_non_pointer_type<Archive,T>::load_only::invoke(Archive &,T &)' with [ Archive=boost::archive::binary_iarchive, T=boost::serialization::nvp<std::vector<C>> ] ../../Libraries\Boost\include\boost-1_32\boost\archive\detail\iserializer.hpp(366) : see reference to class template instantiation 'boost::archive::detail::load_non_pointer_type<Archive,T>::load_only' being compiled with [ Archive=boost::archive::binary_iarchive, T=boost::serialization::nvp<std::vector<C>> ] ../../Libraries\Boost\include\boost-1_32\boost\archive\detail\iserializer.hpp(331) : while compiling class-template member function 'void boost::archive::detail::load_non_pointer_type<Archive,T>::invoke(Archive &,T &)' with [ Archive=boost::archive::binary_iarchive, T=boost::serialization::nvp<std::vector<C>> ] ../../Libraries\Boost\include\boost-1_32\boost\archive\detail\iserializer.hpp(529) : see reference to class template instantiation 'boost::archive::detail::load_non_pointer_type<Archive,T>' being compiled with [ Archive=boost::archive::binary_iarchive, T=boost::serialization::nvp<std::vector<C>> ] ../../Libraries\Boost\include\boost-1_32\boost\archive\basic_binary_iarchive.hpp(66) : see reference to function template instantiation 'void boost::archive::load<Archive,T>(Archive &,T &)' being compiled with [ Archive=boost::archive::binary_iarchive, T=boost::serialization::nvp<std::vector<C>> ] ../../Libraries\Boost\include\boost-1_32\boost\archive\binary_iarchive.hpp(45) : see reference to function template instantiation 'void boost::archive::basic_binary_iarchive<Archive>::load_override<T>(T &,int)' being compiled with [ Archive=boost::archive::binary_iarchive, T=boost::serialization::nvp<std::vector<C>> ] ../../Libraries\Boost\include\boost-1_32\boost\archive\detail\interface_iarchive.hpp(105) : see reference to function template instantiation 'void boost::archive::binary_iarchive_impl<Archive>::load_override<T>(T &,int)' being compiled with [ Archive=boost::archive::binary_iarchive, T=boost::serialization::nvp<std::vector<C>> ] ../../Libraries\Boost\include\boost-1_32\boost\archive\detail\interface_iarchive.hpp(111) : see reference to function template instantiation 'Archive &boost::archive::detail::interface_iarchive<Archive>::operator >><T>(const T &)' being compiled with [ Archive=boost::archive::binary_iarchive, T=boost::serialization::nvp<std::vector<C>> ] </errormessage>

Klaus Nowikow <nowikow <at> decomsys.com> writes:
when I compile the code below (with MSVC 7.1), I get an error telling me that "'serialize' : is not a member of 'std::vector<_Ty>'". I will post the exact error message below the code.
Hm. I did som more resarch and found the following: Whe I either remove the BOOST_SERIALIZATION_NVP() macros or change the lines ar << BOOST_SERIALIZATION_NVP(object); and ar >> BOOST_SERIALIZATION_NVP(object); to ar & BOOST_SERIALIZATION_NVP(object); it also works. Regards, Klaus

For one thing ar & BOOST_SERIALIZATION_NVP(this->m_); isn't a good idea. This will fail when serialiized as xml as an xml attribute can't contain an ">" character. But the main problem is you're using save/load without BOOST_SERIALIZATION_MEMBER_SPLIT() Robert Ramey Klaus Nowikow wrote:
Klaus Nowikow <nowikow <at> decomsys.com> writes:
when I compile the code below (with MSVC 7.1), I get an error telling me that "'serialize' : is not a member of 'std::vector<_Ty>'". I will post the exact error message below the code.
Hm. I did som more resarch and found the following: Whe I either remove the BOOST_SERIALIZATION_NVP() macros or change the lines
ar << BOOST_SERIALIZATION_NVP(object);
and
ar >> BOOST_SERIALIZATION_NVP(object);
to
ar & BOOST_SERIALIZATION_NVP(object);
it also works.
Regards,
Klaus

Robert Ramey <ramey <at> rrsd.com> writes:
For one thing
ar & BOOST_SERIALIZATION_NVP(this->m_);
isn't a good idea. This will fail when serialiized as xml as an xml attribute can't contain an ">" character.
True. Of course I would use something like ar & boost::make_nvp("MyTag", this->m_); in production code.
But the main problem is you're using save/load without BOOST_SERIALIZATION_MEMBER_SPLIT()
No, I don't think so. The structs A, B, and C have serialize() member functions. The save() and load() functions are not the serialization functions but only two arbitrary functions that create an archive and use it to save or load an object. I should have called them foo() and bar() :-) -- which i tried just now, just to be sure, and the error remains. -- Klaus
participants (2)
-
Klaus Nowikow
-
Robert Ramey