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@lists.boost.org> 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@lists.boost.org
https://lists.boost.org/mailman/listinfo.cgi/boost-users