demo_pimpl_A.cpp 1.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445
  1. /////////1/////////2/////////3/////////4/////////5/////////6/////////7/////////8
  2. // demo_pimpl_A.cpp
  3. // (C) Copyright 2002 Robert Ramey - http://www.rrsd.com .
  4. // Use, modification and distribution is subject to the Boost Software
  5. // License, Version 1.0. (See accompanying file LICENSE_1_0.txt or copy at
  6. // http://www.boost.org/LICENSE_1_0.txt)
  7. #include <boost/archive/text_iarchive.hpp>
  8. #include <boost/archive/text_oarchive.hpp>
  9. #include "demo_pimpl_A.hpp"
  10. // "hidden" definition of class B
  11. struct B {
  12. int b;
  13. template<class Archive>
  14. void serialize(Archive & ar, const unsigned int /* file_version */){
  15. ar & b;
  16. }
  17. };
  18. A::A() :
  19. pimpl(new B)
  20. {}
  21. A::~A(){
  22. delete pimpl;
  23. }
  24. // now we can define the serialization for class A
  25. template<class Archive>
  26. void A::serialize(Archive & ar, const unsigned int /* file_version */){
  27. ar & pimpl;
  28. }
  29. // without the explicit instantiations below, the program will
  30. // fail to link for lack of instantiantiation of the above function
  31. // note: the following failed to fix link errors for vc 7.0 !
  32. template void A::serialize<boost::archive::text_iarchive>(
  33. boost::archive::text_iarchive & ar,
  34. const unsigned int file_version
  35. );
  36. template void A::serialize<boost::archive::text_oarchive>(
  37. boost::archive::text_oarchive & ar,
  38. const unsigned int file_version
  39. );