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

后端 未结 3 551
余生分开走
余生分开走 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:45

    Supplementary Information to sehe's first solution:

    The solution requires two-phase lookup and or argument dependent lookup. Unfortunately, MSVC does not yet support this to its full extent.

    Compiling this in VS Community 2019 16.1.6 with boost 1.70 results in an obscure error:

    Error   C2063    'boost::serialization::serialize': not a function
    

    Even though conformance mode is enabled through the /permissive- flag and the latest language standard /std::c++latest is selected, as described in this MSVC Blog Post.

    Adding the typename qualifier to the friend declaration solves the problem:

    template  friend void boost::serialization::serialize(typename Ar&, A&, const unsigned);
    

    Even more interestingly frustratingly:

    if class A is not a templated class, then it doesn't work either way, same error as above... Example code: http://coliru.stacked-crooked.com/a/ecfbb39d5975d753

提交回复
热议问题