serialization auto_ptr std::string

I'm including serialization in my library and am running into problems. One of my class include an std::auto_ptr <std::string> I'm including #include <boost/serialization/string.hpp> to handle the string serialization i downloaded the serialization example for an auto_ptr and modified it to allow for XML serialization (see end of email). But when i compile get the following error saying: error: 'struct std::basic_string<char, std::char_traits<char>, std::allocator<char> >' has no member named 'serialize' If i replace the std::auto_ptr <std::string> with just std::string it works, so i assume something is wrong with my auto_ptr code Feel free to ask me more question or send me beginners advice as i'm just beginning with BOOST. Thanks auto_ptrSerialization.hpp: #include <list> #include <memory> #include <fstream> #include <boost/config.hpp> // std::autoptr inteface wrong in dinkumware #include <boost/detail/workaround.hpp> #include <boost/archive/xml_iarchive.hpp> #include <boost/archive/xml_oarchive.hpp> #include <boost/detail/workaround.hpp> #include <boost/serialization/split_free.hpp> namespace boost { namespace serialization { ///////////////////////////////////////////////////////////// // implement serialization for auto_ptr<T> // note: this must be added to the boost namespace in order to // be called by the library template<class Archive, class T> inline void save( Archive & ar, const std::auto_ptr<T> &t, const unsigned int file_version ){ // only the raw pointer has to be saved // the ref count is rebuilt automatically on load T *objectPtr = t.get(); ar << BOOST_SERIALIZATION_NVP(objectPtr); } template<class Archive, class T> inline void load( Archive & ar, std::auto_ptr<T> &t, const unsigned int file_version ){ T *objectPtr; ar >> BOOST_SERIALIZATION_NVP(objectPtr); // note that the reset automagically maintains the reference count #if BOOST_WORKAROUND(BOOST_DINKUMWARE_STDLIB, == 1) t.release(); t = std::auto_ptr<T>(objectPtr); #else t.reset(objectPtr); #endif } // split non-intrusive serialization function member into separate // non intrusive save/load member functions template<class Archive, class T> inline void serialize( Archive & ar, std::auto_ptr<T> &t, const unsigned int file_version ){ split_free(ar, t, file_version); } } // namespace serialization } // namespace boost Best, Olivier Destrebecq olivierd@real.com

add #include <boost/serialization/string.hpp> Robert Ramey Olivier Destrebecq wrote:
I'm including serialization in my library and am running into problems.
One of my class include an std::auto_ptr <std::string> I'm including #include <boost/serialization/string.hpp> to handle the string serialization
i downloaded the serialization example for an auto_ptr and modified it to allow for XML serialization (see end of email).
But when i compile get the following error saying: error: 'struct std::basic_string<char, std::char_traits<char>, std::allocator<char> >' has no member named 'serialize'
If i replace the std::auto_ptr <std::string> with just std::string it works, so i assume something is wrong with my auto_ptr code Feel free to ask me more question or send me beginners advice as i'm just beginning with BOOST. Thanks
auto_ptrSerialization.hpp:
#include <list> #include <memory> #include <fstream>
#include <boost/config.hpp> // std::autoptr inteface wrong in dinkumware #include <boost/detail/workaround.hpp>
#include <boost/archive/xml_iarchive.hpp> #include <boost/archive/xml_oarchive.hpp> #include <boost/detail/workaround.hpp>
#include <boost/serialization/split_free.hpp>
namespace boost { namespace serialization {
///////////////////////////////////////////////////////////// // implement serialization for auto_ptr<T> // note: this must be added to the boost namespace in order to // be called by the library template<class Archive, class T> inline void save( Archive & ar, const std::auto_ptr<T> &t, const unsigned int file_version ){ // only the raw pointer has to be saved // the ref count is rebuilt automatically on load T *objectPtr = t.get(); ar << BOOST_SERIALIZATION_NVP(objectPtr); }
template<class Archive, class T> inline void load( Archive & ar, std::auto_ptr<T> &t, const unsigned int file_version ){ T *objectPtr; ar >> BOOST_SERIALIZATION_NVP(objectPtr); // note that the reset automagically maintains the reference count #if BOOST_WORKAROUND(BOOST_DINKUMWARE_STDLIB, == 1) t.release(); t = std::auto_ptr<T>(objectPtr); #else t.reset(objectPtr); #endif }
// split non-intrusive serialization function member into separate // non intrusive save/load member functions template<class Archive, class T> inline void serialize( Archive & ar, std::auto_ptr<T> &t, const unsigned int file_version ){ split_free(ar, t, file_version); }
} // namespace serialization } // namespace boost
Best, Olivier Destrebecq olivierd@real.com

I had #include <boost/serialization/string.hpp> in the base class of my class ierarchy that is to be serialized, but still i get the warning. I tried to include it in the auto_ptr serialization file, in the descendant class that serialize the auto_ptr to the string, but no luck. Best, Olivier Destrebecq olivierd@real.com On Apr 24, 2006, at 12:44 PM, Olivier Destrebecq wrote:
I'm including serialization in my library and am running into problems.
One of my class include an std::auto_ptr <std::string> I'm including #include <boost/serialization/string.hpp> to handle the string serialization
i downloaded the serialization example for an auto_ptr and modified it to allow for XML serialization (see end of email).
But when i compile get the following error saying: error: 'struct std::basic_string<char, std::char_traits<char>, std::allocator<char> >' has no member named 'serialize'
If i replace the std::auto_ptr <std::string> with just std::string it works, so i assume something is wrong with my auto_ptr code Feel free to ask me more question or send me beginners advice as i'm just beginning with BOOST. Thanks
auto_ptrSerialization.hpp:
#include <list> #include <memory> #include <fstream>
#include <boost/config.hpp> // std::autoptr inteface wrong in dinkumware #include <boost/detail/workaround.hpp>
#include <boost/archive/xml_iarchive.hpp> #include <boost/archive/xml_oarchive.hpp> #include <boost/detail/workaround.hpp>
#include <boost/serialization/split_free.hpp>
namespace boost { namespace serialization {
///////////////////////////////////////////////////////////// // implement serialization for auto_ptr<T> // note: this must be added to the boost namespace in order to // be called by the library template<class Archive, class T> inline void save( Archive & ar, const std::auto_ptr<T> &t, const unsigned int file_version ){ // only the raw pointer has to be saved // the ref count is rebuilt automatically on load T *objectPtr = t.get(); ar << BOOST_SERIALIZATION_NVP(objectPtr); }
template<class Archive, class T> inline void load( Archive & ar, std::auto_ptr<T> &t, const unsigned int file_version ){ T *objectPtr; ar >> BOOST_SERIALIZATION_NVP(objectPtr); // note that the reset automagically maintains the reference count #if BOOST_WORKAROUND(BOOST_DINKUMWARE_STDLIB, == 1) t.release(); t = std::auto_ptr<T>(objectPtr); #else t.reset(objectPtr); #endif }
// split non-intrusive serialization function member into separate // non intrusive save/load member functions template<class Archive, class T> inline void serialize( Archive & ar, std::auto_ptr<T> &t, const unsigned int file_version ){ split_free(ar, t, file_version); }
} // namespace serialization } // namespace boost
Best, Olivier Destrebecq olivierd@real.com
participants (2)
-
Olivier Destrebecq
-
Robert Ramey