Boost logo

Boost Users :

Subject: Re: [Boost-users] Compiler does not give error for missing serialize function
From: Robert Ramey (ramey_at_[hidden])
Date: 2016-04-22 11:04:23


On 4/22/16 5:38 AM, Elizabeta wrote:
> Hi
> I have the following code :
>
> class MyClass
> {
> private:
> friend class boost::serialization::access;
> template<class Archive>
> void serialize(Archive &ar, const unsigned int version) {}
> };
>
> class MyClass2 : public MyClass {};
>
> MyClass2* ss = new MyClass2;
> std::ofstream ofs("C:\\test.xml");
> boost::archive::xml_oarchive oa(ofs);
> oa & boost::serialization::make_nvp("test",ss);
>
> I am serializing trough the derived class pointer. The derived class doesnot
> have serialize function. The Base have. And I was expecting compiler to give
> me error that MyClass2 doesnot have serialize function. But this code
> compiles without errors. I am using vs2010.

the friend gives the serialization library access to your private
serialization function.

But I was surprised by this as well. I don't think it's wrong though.

Robert Ramey


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