Jump to content
  • Advertisement
Sign in to follow this  
NeilFang

newbie question about boost::serialization

This topic is 3968 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

The code blow copy from the Boost::serialization tutorial,A Very Simple Case section
int main() {
    // create and open a character archive for output
    std::ofstream ofs("filename");

    // create class instance
    const gps_position g(35, 59, 24.567f);

    // save data to archive
    {
        boost::archive::text_oarchive oa(ofs);
        // write class instance to archive
        oa << g;
    	// archive and stream closed when destructors are called
}


If I remove the const away from instance define, as this "gps_position g(35, 59, 24.567f);", then I get a compile error. Could anybody tell why? Only const object can be serialized?

Share this post


Link to post
Share on other sites
Advertisement
Quote:
Original post by Kylotan
I don't know. What is the compile error you get?


I'm using Visual Studio 2005, the compile error is :

1>d:\boost\boost\archive\detail\oserializer.hpp(566) : error C2027: use of undefined type 'boost::STATIC_ASSERTION_FAILURE<x>'
1> with
1> [
1> x=false
1> ]
1> d:\boost\boost\archive\detail\common_oarchive.hpp(62) : see reference to function template instantiation 'void boost::archive::save<Archive,T>(Archive &,T &)' being compiled
1> with
1> [
1> Archive=boost::archive::text_oarchive,
1> T=gps_position
1> ]
1> d:\boost\boost\archive\basic_text_oarchive.hpp(75) : see reference to function template instantiation 'void boost::archive::detail::common_oarchive<Archive>::save_override<T>(T &,int)' being compiled
1> with
1> [
1> Archive=boost::archive::text_oarchive,
1> T=gps_position
1> ]
1> d:\boost\boost\archive\detail\interface_oarchive.hpp(79) : see reference to function template instantiation 'void boost::archive::basic_text_oarchive<Archive>::save_override<T>(T &,int)' being compiled
1> with
1> [
1> Archive=boost::archive::text_oarchive,
1> T=gps_position
1> ]
1> d:\lpython\tryboost\simpleboost\example.cpp(47) : see reference to function template instantiation 'Archive &boost::archive::detail::interface_oarchive<Archive>::operator <<<gps_position>(T &)' being compiled
1> with
1> [
1> Archive=boost::archive::text_oarchive,
1> T=gps_position
1> ]

Share this post


Link to post
Share on other sites
That is intentional. See this doc about why boost::serialization fails to compile with non-const values. To be honest, that doesn't make a lot of sense to me and I haven't taken the time to read it carefully. I haven't managed to get boost::serialization to work for anything but trivial examples. The order that headers are included is very touchy and there are some other issues, but those are supposed to be improved in Boost 1.36 or something like that. If you can get it to work before then, that's great, but I might recommend you look for other solutions until then...

Share this post


Link to post
Share on other sites
Sign in to follow this  

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

GameDev.net is your game development community. Create an account for your GameDev Portfolio and participate in the largest developer community in the games industry.

Sign me up!