-
Notifications
You must be signed in to change notification settings - Fork 780
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Better documentation on when <cereal/types/polymorphic.hpp> is required #193
Comments
Sounds reasonable to me. Any suggestions on how to best phrase it? |
How about on http://uscilab.github.io/cereal/pointers.html : "If your smart pointers are serializing a subclassed object, such as a derived class, you must include the cereal/include/polymorphic.hpp header, regardless of whether or not you are using cereal's support for dynamic instancing of polymorphic types." And for fixing the warning message in the header: "If you are using a smart pointer to a derived class, make sure to include cereal/include/polymorphic.hpp . " Feel free to rewrite this for intelligibility... |
I'm curious if this is such a common thing to have happen, if we shouldn't just have the shared-ptr serialization code just include polymorphic by default? |
I'm fine with that. I don't think there's too much of a compile-time penalty for just including the file. We would need to update all of the documentation to reflect the change. What do you think, @AzothAmmo ? |
I vote to automatically include cereal/types/polymorphic.hpp whenever cereal/types/memory.hpp is included. shared_ptr only would ever be practically used to serialize complicated structs and classes, not basic data types. In the worst case, compilation time is slowed trivially, and in the best case things just magically work out of the box for the average programmer. Anyone else trying to serialize containers of shared_ptrs to derived classes will run into this issue, I suspect. But I certainly don't know this system very well.. |
I have no real objection to this. |
Great, let's do it. I've put it on the v1.2.0 milestone, as making this change will require some tedious documentation edits. In this case, polymorphic.hpp should probably be moved out of types, and into details (maybe just merged with polymorphic_impl.hpp). |
Thanks! |
I think the best way to go about this is to just include polymorphic in memory and leave the file structure as-is, so we don't introduce a breaking change (plus I like the current organization). |
Since picking and choosing headers is technically a compilation
|
I spent a few hours beating my head against a particular problem until the solution became clear, and I'd like to save the next guy the same time. In particular, I was trying to serialize something like the following structure:
and I kept getting the following error:
A serialization function existed and was working for MySubclass, so I couldn't see what all the fuss was about.
The actual source of the error, however, was that I had apparently failed to include cereal/types/polymorphic.hpp, and so myMap could not work out a specialization for MySubclass.
It would be helpful to both amend the documentation and the warning message to indicate that polymorphic.hpp needs to be included any time you serialize a derived class stored within a shared_ptr, regardless of whether or not there are multiple dependent serialized classes.
The text was updated successfully, but these errors were encountered: