I am using boost (de)serialization to reconstruct classes without public default ctors, by design. I declare a private default ctor and declare the boost access class as a friend, and it uses the default ctor as part of its deserialization process. But it can't reconstruct a std::pair
unless I make the default ctor public. I'd rather declare friendship, but I can't figure out how.
Below is a simplified example:
class PrivateDC
{
private:
friend class PrivateDCFriend;
friend struct std::pair<int, PrivateDC>;
PrivateDC() = default;
};
class PrivateDCFriend
{
void f() const
{
PrivateDC a; // this works, proves friendship
std::pair<int, PrivateDC> b; // gets compile error
}
};
The error is "no matching constructor for initialization of 'std::pair<int, PrivateDC>'". I don't get the error if the default ctor is public.
How can I declare std::pair
as a friend so this will work?