Boost logo

Boost Users :

Subject: [Boost-users] [serialization] "Archive" type turns into abstract class during save/load!
From: r_at_[hidden]
Date: 2017-07-13 13:43:08


In a member load function function I call a static method that loads
another archive file, i.e. something like this:

```c++
struct Bar;
struct Foo
{
     std::shared_ptr<Bar> data;
     template <class Archive>
     void load(Archive& archive, const unsigned /*version*/)
     {
         std::string key;
         archive >> key;
         data = Bar::loadSomewhere<Archive>(std::move(key));
     }
};
struct Bar
{
     template <class Archive>
     std::shared_ptr<Bar> loadSomewhere(std::string key)
     {
         std::ifstream input(key);
         Archive ar(input);
         std::shared_ptr<Bar> bar(new Bar());
         ar >> *bar;
         return bar;
     }
};
```

The problem is that `Bar::loadSomewhere` is passed a
`boost::archive::polymorphic_iarchive`, while I invoke the serialization
library with a `boost::archive::xml_iarchive`. This is an abstract
class, so I can't instantiate it! So somewhere down the road the
`xml_iarchive` is turned into a `polymorphic_iarchive`. I would like to
prevent this from happening, because I instantiate an `Archive` object
in the `Bar::loadSomewhere` function. How can I get around this problem?


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