Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8693351
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 13, 20262026-06-13T00:31:42+00:00 2026-06-13T00:31:42+00:00

Does the boost serialization library support serialization of std::unique_ptr? I tried to compile the

  • 0

Does the boost serialization library support serialization of std::unique_ptr?
I tried to compile the code below, but if I include the
boost::archive::text_oarchive oa(ofs); oa << g; line,

the compiler (btw gcc4.7 with -std=c++11 flag) throws an error

/usr/include/boost/serialization/access.hpp:118:9: error: ‘class std::unique_ptr’ has no member named ‘serialize’

#include <iostream>
#include <memory>
#include <fstream>
#include <boost/archive/text_oarchive.hpp>
#include <boost/archive/text_iarchive.hpp>
class MyDegrees
{
public:
  void setDeg(int d){deg = d;}
  int getDeg()const {return deg;}
private:
  friend class boost::serialization::access;
    template<class Archive>
    void serialize(Archive & ar, const unsigned int version)
    { ar & deg; }
  int deg;
};
class gps_position
{
private:
    friend class boost::serialization::access;
    template<class Archive>
    void serialize(Archive & ar, const unsigned int version)
    { ar & degrees; }
    std::unique_ptr<MyDegrees> degrees;
public:
    gps_position(): degrees(std::unique_ptr<MyDegrees>(new MyDegrees)){};
    void setDeg(int d){degrees->setDeg(d);}
    int getDeg() const {return degrees->getDeg();}
};
int main()
{
    std::ofstream ofs("filename");
    gps_position g;
    g.setDeg(45);
    std::cout<<g.getDeg()<<std::endl;
    {// compiler error, fine if commented out
        boost::archive::text_oarchive oa(ofs); oa << g;
    }
  return 0;
}
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-13T00:31:43+00:00Added an answer on June 13, 2026 at 12:31 am

    No, there is no out of the box adaption. You will need to provide a non-intrusive adapter yourself. See the tutorial here to get an idea how to do that.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

If I'm using Boost Serialization to serialize an Integer: #include <boost/archive/text_oarchive.hpp> #include <iostream> int
Why does the following code not allow foo(ptr) to be called ? #include <boost/scoped_ptr.hpp>
The following does not compile: class Foo { public: Foo( boost::shared_ptr< Bar > arg
What is the purpose of using the Boost.MPI library? Does it increase performance? And
I am working on a client-server application that uses boost::serialization library for it's serialization
I was trying to compile some code that uses Boost (1.49), with Clang(& libc++)
Does Boost have a support for MD5 checksum calculation? Is yes, how to you
What is std::pair for, why would I use it, and what benefits does boost::compressed_pair
How does pointer tracking work in boost serialization? I am using it to serialize
I am using boost serialization on windows, and I wanted to test my code

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.