Get private data members for non intrusive boost serialization C++

后端 未结 3 557
余生分开走
余生分开走 2020-12-06 03:01

I have tried providing getters of class A for my non-member serialize() function` since accessing from members is private.

template         


        
3条回答
  •  暗喜
    暗喜 (楼主)
    2020-12-06 03:40

    Just for additional info: In order to get the first solution from sehe working:

    You need a forward decleration of the friends method like this:

    // Boost
    #include 
    
    class ClassB;
    
    namespace boost{
    namespace serialization {
        template  void serialize(Ar&,ClassB&,const unsigned);
    }
    }
    
    class ClassB: public ClassA{
    
    private:
        template  friend void boost::serialization::serialize(Ar&,ClassA&,const unsigned);
    public:
        ClassA();
        virtual ~ClassA();
    };
    

    Took me a while to get it working.

    Cheers

提交回复
热议问题