Boost logo

Boost Users :

From: mik (mirko.cambi_at_[hidden])
Date: 2019-12-23 00:43:01


Hi,

basically, you need to add "#include <boost/serialization/valarray.hpp>",
and correct some other bugs...

#include <iostream>
#include <valarray>
#include <boost/archive/text_oarchive.hpp>
#include <boost/serialization/valarray.hpp>

class A {
    std::valarray<int> member_one;
    std::valarray<float> member_two;
    friend class boost::serialization::access;

    template<class Archive>
        void serialize(Archive &ar, const unsigned int version){
        ar & member_one;
        ar & member_two;
    }
};

int main() {
    A p;
    {
        boost::archive::text_oarchive oarchive(std::cout);
        oarchive << p;
    }
    return 0;
}

Regards,
    Mirko

On Sun, Dec 22, 2019 at 3:13 AM Meik via Boost-users <
boost-users_at_[hidden]> wrote:

> Hello,
>
> I am new to C++ and thus new to Boost. My goal is to serialize a class
> containing multiple std::valarrays with primitives as content.
>
> The code I wrote to achieve that(minimal example to reproduce):
>
> #include <iostream>
> #include <boost/archive/text_oarchive.hpp>
>
> class A {
> valarray<int> member_one;
> valarray<float> member_two;
> friend class boost::serialization::access;
>
> template<class Archive>
> void serialize(Archive &ar, const unsigned int version){
> ar & member_one;
> ar & member_two
> }
> }
> int main(int argc, char* argv[]) {
> boost::archive::text_oarchive oarchive(cout);
> oarchive << p;
> return 0;
> }
>
> When compiling this, the following error is given:
>
> error: class std::valarray<int> has no member names serialize
>
> I'd appreciate if you could let me know how to correctly serialize said
> std::valarray.
>
> Kind regards,
> Meik S.
>
> _______________________________________________
> Boost-users mailing list
> Boost-users_at_[hidden]
> https://lists.boost.org/mailman/listinfo.cgi/boost-users
>



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