|
Boost : |
From: Paul Roberts (usenet_at_[hidden])
Date: 2008-03-23 15:20:49
Robert Ramey wrote:
> it would seem to me that a private constructor in this context
> is a compile time error.
>
> In this case we've got
>
> A A::a;
>
> created at pre-main time by the C++ runtime initialization. The
> constructor is public - as it must be to be used in this way. By
> the same token, the destructor would have to be public also.
>
Sorry, Robert, that was an unfortunate and distracting artifact of my
repro case. Here's another repro without the static instance of A.
Here, we have class B containing an instance of A, and A lists B as a
friend, so A's private destructor is legal. The error in
boost/serialization/extended_type_info_typeid.hpp is the same.
-- Paul Roberts paul at pwroberts dot com http://www.m3fe.com/
#include <boost/serialization/access.hpp>
#include <boost/archive/binary_oarchive.hpp>
#include <fstream>
class A
{
friend class boost::serialization::access;
friend class B;
private:
A() {}
~A() {}
template<typename Archive> void serialize(Archive& ar, const unsigned int version)
{
}
};
class B
{
friend class boost::serialization::access;
A a;
template<typename Archive> void serialize(Archive& ar, const unsigned int version)
{
ar << a;
}
};
int main()
{
std::ofstream ofs("hi");
{
boost::archive::binary_oarchive oa(ofs);
B b;
oa << b;
}
}
/*
1>------ Build started: Project: 2k8test, Configuration: Release Win32 ------
1>Compiling...
1>serialization_fun.cpp
1>C:\dev\boost-trunk\boost/serialization/extended_type_info_typeid.hpp(118) : error C2248: 'A::~A' : cannot access private member declared in class 'A'
1> .\serialization_fun.cpp(16) : compiler has generated 'A::~A' here
1> .\serialization_fun.cpp(6) : see declaration of 'A'
1> C:\dev\boost-trunk\boost/serialization/extended_type_info_typeid.hpp(117) : while compiling class template member function 'void boost::serialization::extended_type_info_typeid<T>::destroy(const void *const ) const'
1> with
1> [
1> T=A
1> ]
1> C:\dev\boost-trunk\boost/archive/detail/oserializer.hpp(110) : see reference to class template instantiation 'boost::serialization::extended_type_info_typeid<T>' being compiled
1> with
1> [
1> T=A
1> ]
1> C:\dev\boost-trunk\boost/archive/detail/oserializer.hpp(107) : while compiling class template member function 'boost::archive::detail::oserializer<Archive,T>::oserializer(void)'
1> with
1> [
1> Archive=boost::archive::binary_oarchive,
1> T=A
1> ]
1> C:\dev\boost-trunk\boost/archive/detail/oserializer.hpp(234) : see reference to class template instantiation 'boost::archive::detail::oserializer<Archive,T>' being compiled
1> with
1> [
1> Archive=boost::archive::binary_oarchive,
1> T=A
1> ]
1> C:\dev\boost-trunk\boost/archive/detail/oserializer.hpp(228) : while compiling class template member function 'void boost::archive::detail::save_non_pointer_type<Archive,T>::save_standard::invoke(Archive &,const T &)'
1> with
1> [
1> Archive=boost::archive::binary_oarchive,
1> T=A
1> ]
1> C:\dev\boost-trunk\boost/archive/detail/oserializer.hpp(292) : see reference to class template instantiation 'boost::archive::detail::save_non_pointer_type<Archive,T>::save_standard' being compiled
1> with
1> [
1> Archive=boost::archive::binary_oarchive,
1> T=A
1> ]
1> C:\dev\boost-trunk\boost/archive/detail/oserializer.hpp(280) : while compiling class template member function 'void boost::archive::detail::save_non_pointer_type<Archive,T>::invoke(Archive &,const T &)'
1> with
1> [
1> Archive=boost::archive::binary_oarchive,
1> T=A
1> ]
1> C:\dev\boost-trunk\boost/archive/detail/oserializer.hpp(498) : see reference to class template instantiation 'boost::archive::detail::save_non_pointer_type<Archive,T>' being compiled
1> with
1> [
1> Archive=boost::archive::binary_oarchive,
1> T=A
1> ]
1> C:\dev\boost-trunk\boost/archive/detail/common_oarchive.hpp(64) : see reference to function template instantiation 'void boost::archive::save<Archive,const T>(Archive &,const T &)' being compiled
1> with
1> [
1> Archive=boost::archive::binary_oarchive,
1> T=A
1> ]
1> C:\dev\boost-trunk\boost/archive/array/oarchive.hpp(118) : see reference to function template instantiation 'void boost::archive::detail::common_oarchive<Archive>::save_override<const T>(T &,int)' being compiled
1> with
1> [
1> Archive=boost::archive::binary_oarchive,
1> T=A
1> ]
1> C:\dev\boost-trunk\boost/archive/basic_binary_oarchive.hpp(64) : see reference to function template instantiation 'void boost::archive::array::oarchive<Archive>::save_override<T>(const T &,unsigned int)' being compiled
1> with
1> [
1> Archive=boost::archive::binary_oarchive,
1> T=A
1> ]
1> C:\dev\boost-trunk\boost/archive/binary_oarchive_impl.hpp(45) : see reference to function template instantiation 'void boost::archive::basic_binary_oarchive<Archive>::save_override<T>(const T &,int)' being compiled
1> with
1> [
1> Archive=boost::archive::binary_oarchive,
1> T=A
1> ]
1> C:\dev\boost-trunk\boost/archive/detail/interface_oarchive.hpp(63) : see reference to function template instantiation 'void boost::archive::binary_oarchive_impl<Archive,Elem,Tr>::save_override<T>(T &,int)' being compiled
1> with
1> [
1> Archive=boost::archive::binary_oarchive,
1> Elem=char,
1> Tr=std::char_traits<char>,
1> T=A
1> ]
1> .\serialization_fun.cpp(25) : see reference to function template instantiation 'Archive &boost::archive::detail::interface_oarchive<Archive>::operator <<<A>(T &)' being compiled
1> with
1> [
1> Archive=boost::archive::binary_oarchive,
1> T=A
1> ]
1> C:\dev\boost-trunk\boost/serialization/access.hpp(109) : see reference to function template instantiation 'void B::serialize<Archive>(Archive &,const unsigned int)' being compiled
1> with
1> [
1> Archive=boost::archive::binary_oarchive
1> ]
1> C:\dev\boost-trunk\boost/serialization/serialization.hpp(81) : see reference to function template instantiation 'void boost::serialization::access::serialize<Archive,T>(Archive &,T &,const unsigned int)' being compiled
1> with
1> [
1> Archive=boost::archive::binary_oarchive,
1> T=B
1> ]
1> C:\dev\boost-trunk\boost/serialization/serialization.hpp(140) : see reference to function template instantiation 'void boost::serialization::serialize<Archive,T>(Archive &,T &,const unsigned int)' being compiled
1> with
1> [
1> Archive=boost::archive::binary_oarchive,
1> T=B
1> ]
1> C:\dev\boost-trunk\boost/archive/detail/oserializer.hpp(147) : see reference to function template instantiation 'void boost::serialization::serialize_adl<Archive,T>(Archive &,T &,const unsigned int)' being compiled
1> with
1> [
1> Archive=boost::archive::binary_oarchive,
1> T=B
1> ]
1> C:\dev\boost-trunk\boost/archive/detail/oserializer.hpp(139) : while compiling class template member function 'void boost::archive::detail::oserializer<Archive,T>::save_object_data(boost::archive::detail::basic_oarchive &,const void *) const'
1> with
1> [
1> Archive=boost::archive::binary_oarchive,
1> T=B
1> ]
1> C:\dev\boost-trunk\boost/archive/detail/oserializer.hpp(234) : see reference to class template instantiation 'boost::archive::detail::oserializer<Archive,T>' being compiled
1> with
1> [
1> Archive=boost::archive::binary_oarchive,
1> T=B
1> ]
1> C:\dev\boost-trunk\boost/archive/detail/oserializer.hpp(228) : while compiling class template member function 'void boost::archive::detail::save_non_pointer_type<Archive,T>::save_standard::invoke(Archive &,const T &)'
1> with
1> [
1> Archive=boost::archive::binary_oarchive,
1> T=B
1> ]
1> C:\dev\boost-trunk\boost/archive/detail/oserializer.hpp(292) : see reference to class template instantiation 'boost::archive::detail::save_non_pointer_type<Archive,T>::save_standard' being compiled
1> with
1> [
1> Archive=boost::archive::binary_oarchive,
1> T=B
1> ]
1> C:\dev\boost-trunk\boost/archive/detail/oserializer.hpp(280) : while compiling class template member function 'void boost::archive::detail::save_non_pointer_type<Archive,T>::invoke(Archive &,const T &)'
1> with
1> [
1> Archive=boost::archive::binary_oarchive,
1> T=B
1> ]
1> C:\dev\boost-trunk\boost/archive/detail/oserializer.hpp(498) : see reference to class template instantiation 'boost::archive::detail::save_non_pointer_type<Archive,T>' being compiled
1> with
1> [
1> Archive=boost::archive::binary_oarchive,
1> T=B
1> ]
1> C:\dev\boost-trunk\boost/archive/detail/common_oarchive.hpp(64) : see reference to function template instantiation 'void boost::archive::save<Archive,const T>(Archive &,const T &)' being compiled
1> with
1> [
1> Archive=boost::archive::binary_oarchive,
1> T=B
1> ]
1> C:\dev\boost-trunk\boost/archive/array/oarchive.hpp(118) : see reference to function template instantiation 'void boost::archive::detail::common_oarchive<Archive>::save_override<const T>(T &,int)' being compiled
1> with
1> [
1> Archive=boost::archive::binary_oarchive,
1> T=B
1> ]
1> C:\dev\boost-trunk\boost/archive/basic_binary_oarchive.hpp(64) : see reference to function template instantiation 'void boost::archive::array::oarchive<Archive>::save_override<T>(const T &,unsigned int)' being compiled
1> with
1> [
1> Archive=boost::archive::binary_oarchive,
1> T=B
1> ]
1> C:\dev\boost-trunk\boost/archive/binary_oarchive_impl.hpp(45) : see reference to function template instantiation 'void boost::archive::basic_binary_oarchive<Archive>::save_override<T>(const T &,int)' being compiled
1> with
1> [
1> Archive=boost::archive::binary_oarchive,
1> T=B
1> ]
1> C:\dev\boost-trunk\boost/archive/detail/interface_oarchive.hpp(63) : see reference to function template instantiation 'void boost::archive::binary_oarchive_impl<Archive,Elem,Tr>::save_override<T>(T &,int)' being compiled
1> with
1> [
1> Archive=boost::archive::binary_oarchive,
1> Elem=char,
1> Tr=std::char_traits<char>,
1> T=B
1> ]
1> .\serialization_fun.cpp(35) : see reference to function template instantiation 'Archive &boost::archive::detail::interface_oarchive<Archive>::operator <<<B>(T &)' being compiled
1> with
1> [
1> Archive=boost::archive::binary_oarchive,
1> T=B
1> ]
1>Build log was saved at "file://c:\dev\work\2k8test\Release\BuildLog.htm"
1>2k8test - 1 error(s), 0 warning(s)
========== Build: 0 succeeded, 1 failed, 0 up-to-date, 0 skipped ==========
*/
Boost list run by bdawes at acm.org, gregod at cs.rpi.edu, cpdaniel at pacbell.net, john at johnmaddock.co.uk