|
Boost Users : |
Subject: [Boost-users] [Serialization] Std::string's pointer can't be serialized.
From: Moch Ramis (mocramis_at_[hidden])
Date: 2010-06-30 05:26:05
Hello.
I recently try to use boost.Serialization and it works fine until i
try to serialize a string pointer. With a string pointer, the compiler
(gcc 4.4.1) can't resolve a type and print the error: "error: struct
std::basic_string<char, std::char_traits<char>, std::allocator<char>
> has no member named serialize"
Here a schoolish example that fails to compile:
______________________________________________________
#include <boost/archive/text_oarchive.hpp>
#include <boost/archive/text_iarchive.hpp>
#include <boost/serialization/string.hpp>
#include <fstream>
#include <string>
int main()
{
std::string* s=new std::string("some text");
std::ofstream of("file.txt");
{
boost::archive::text_oarchive oa(of);
// write class instance to archive
oa << s;
// archive and stream closed when destructors are called
}
delete s;
return 0;
}
__________________________________________________________
and the gcc output is:
-------------- Build: Debug in Boost_Serialize_Test ---------------
Compiling: main.cpp
In file included from /usr/include/boost/serialization/split_member.hpp:23,
from /usr/include/boost/serialization/nvp.hpp:33,
from /usr/include/boost/serialization/serialization.hpp:17,
from /usr/include/boost/archive/detail/oserializer.hpp:61,
from /usr/include/boost/archive/detail/interface_oarchive.hpp:24,
from /usr/include/boost/archive/detail/common_oarchive.hpp:20,
from /usr/include/boost/archive/basic_text_oarchive.hpp:32,
from /usr/include/boost/archive/text_oarchive.hpp:31,
from /.../main.cpp:2:
/usr/include/boost/serialization/access.hpp: In static member function
static void boost::serialization::access::serialize(Archive&, T&,
unsigned int) [with Archive = boost::archive::text_oarchive, T =
std::basic_string<char, std::char_traits<char>, std::allocator<char>
>]:
/usr/include/boost/serialization/serialization.hpp:74: instantiated
from void boost::serialization::serialize(Archive&, T&, unsigned int)
[with Archive = boost::archive::text_oarchive, T =
std::basic_string<char, std::char_traits<char>, std::allocator<char>
>]
/usr/include/boost/serialization/serialization.hpp:133: instantiated
from void boost::serialization::serialize_adl(Archive&, T&, unsigned
int) [with Archive = boost::archive::text_oarchive, T =
std::basic_string<char, std::char_traits<char>, std::allocator<char>
>]
/usr/include/boost/archive/detail/oserializer.hpp:140: instantiated
from void boost::archive::detail::oserializer<Archive,
T>::save_object_data(boost::archive::detail::basic_oarchive&, const
void*) const [with Archive = boost::archive::text_oarchive, T =
std::basic_string<char, std::char_traits<char>, std::allocator<char>
>]
/.../main.cpp:87: instantiated from here
/usr/include/boost/serialization/access.hpp:109: error: struct
std::basic_string<char, std::char_traits<char>, std::allocator<char>
> has no member named serialize
Process terminated with status 1 (0 minutes, 4 seconds)
1 errors, 0 warnings
----------------------------------------------------------------------------------
I also tried this one codepad. you could see the result here:
I don't know if it's an issue or if i'm using serialize the wrong way
but i would need to serialize strings pointers.
Best regards
Mocramis
Boost-users list run by williamkempf at hotmail.com, kalb at libertysoft.com, bjorn.karlsson at readsoft.com, gregod at cs.rpi.edu, wekempf at cox.net