[serialization] Problem deriving from text_oarchive_impl

Hi, I'm starting to get the hang of this as I slog through, but it's still a bit rough! I'm able to derive a new archive from binary_oarchive_impl, but for some reason, I can't do the same with text_oarchive_impl. Specifically, I get the following error (from MS Visual C++ 8.0, using Boost 1.33.1): 1>..\rsg_text_oarchive.hpp(24) : error C2649: 'basic_text_oprimitive<class std::basic_ostream<char,struct std::char_traits<char> > >' : is not a 'class' 1> ..\rsg_text_oarchive.hpp(40) : see reference to class template instantiation 'rsg_text_oarchive_impl<Archive>' being compiled The similar line in the binary archive works fine. Attached are the two derived archives in question. All I'm trying to do (at this point) is add a short header in the constructor; next, I'll want to add a footer in the destructor. Thanks! -Bob

Argh! Now if only I can remember the attachments! They are the text (broken) and binary (works) versions. My broken text code in question is presented, in part, below. The compiler complains about the second friend line. -- Code -- #include <iostream> #include <ostream> #include <boost/archive/archive_exception.hpp> #include <boost/archive/text_oarchive.hpp> template<class Archive> class rsg_text_oarchive_impl : // don't derive from text_oarchive !!! public boost::archive::text_oarchive_impl<Archive> { typedef rsg_text_oarchive_impl derived_t; #ifndef BOOST_NO_MEMBER_TEMPLATE_FRIENDS public: #else friend class boost::archive::basic_text_oarchive<rsg_text_oarchive_impl<Archive> >; friend class boost::archive::basic_text_oprimitive<std::ostream>; friend class boost::archive::save_access; #endif public: rsg_text_oarchive_impl(std::ostream & os, unsigned int flags = 0) : boost::archive::text_oarchive_impl<Archive>( os, flags | boost::archive::no_header // skip default header checking ) { // use our own header checking if (0 == (flags & boost::archive::no_header)){ os << "<!-- RSG Text Archive -->" << std::endl; this->boost::archive::basic_text_oarchive<Archive>::init(); } } }; -- end Code - more follows here...
-----Original Message----- Subject: [serialization] Problem deriving from text_oarchive_impl
Hi,
I'm starting to get the hang of this as I slog through, but it's still a bit rough! I'm able to derive a new archive from binary_oarchive_impl, but for some reason, I can't do the same with text_oarchive_impl. Specifically, I get the following error (from MS Visual C++ 8.0, using Boost 1.33.1):
1>..\rsg_text_oarchive.hpp(24) : error C2649: 'basic_text_oprimitive<class std::basic_ostream<char,struct std::char_traits<char> > >' : is not a 'class' 1> ..\rsg_text_oarchive.hpp(40) : see reference to class template instantiation 'rsg_text_oarchive_impl<Archive>' being compiled
The similar line in the binary archive works fine. Attached are the two derived archives in question. All I'm trying to do (at this point) is add a short header in the constructor; next, I'll want to add a footer in the destructor.
Thanks! -Bob

This also failed to compile for me with VC 7.1. However it did compile with gcc 3.3, borland 6.64 and comeau. So its safe to say its a compiler problem. In your case you might just make all the member public. Robert Ramey Robert S. Grimes wrote:
Argh! Now if only I can remember the attachments! They are the text (broken) and binary (works) versions. My broken text code in question is presented, in part, below. The compiler complains about the second friend line.
-- Code -- #include <iostream> #include <ostream> #include <boost/archive/archive_exception.hpp> #include <boost/archive/text_oarchive.hpp>
; friend class boost::archive::basic_text_oprimitive<std::ostream>; friend class boost::archive::save_access; #endif
template<class Archive> class rsg_text_oarchive_impl : // don't derive from text_oarchive !!! public boost::archive::text_oarchive_impl<Archive> { typedef rsg_text_oarchive_impl derived_t; #ifndef BOOST_NO_MEMBER_TEMPLATE_FRIENDS public: #else friend class boost::archive::basic_text_oarchive<rsg_text_oarchive_impl<Archive> public: rsg_text_oarchive_impl(std::ostream & os, unsigned int flags = 0) : boost::archive::text_oarchive_impl<Archive>( os, flags | boost::archive::no_header // skip default header checking ) { // use our own header checking if (0 == (flags & boost::archive::no_header)){ os << "<!-- RSG Text Archive -->" << std::endl; this->boost::archive::basic_text_oarchive<Archive>::init(); } } }; -- end Code - more follows here...
-----Original Message----- Subject: [serialization] Problem deriving from text_oarchive_impl
Hi,
I'm starting to get the hang of this as I slog through, but it's still a bit rough! I'm able to derive a new archive from binary_oarchive_impl, but for some reason, I can't do the same with text_oarchive_impl. Specifically, I get the following error (from MS Visual C++ 8.0, using Boost 1.33.1):
1>..\rsg_text_oarchive.hpp(24) : error C2649: 'basic_text_oprimitive<class std::basic_ostream<char,struct std::char_traits<char> > >' : is not a 'class' 1> ..\rsg_text_oarchive.hpp(40) : see reference to class template instantiation 'rsg_text_oarchive_impl<Archive>' being compiled
The similar line in the binary archive works fine. Attached are the two derived archives in question. All I'm trying to do (at this point) is add a short header in the constructor; next, I'll want to add a footer in the destructor.
Thanks! -Bob
_______________________________________________ Boost-users mailing list Boost-users@lists.boost.org http://lists.boost.org/mailman/listinfo.cgi/boost-users

So its safe to say its a compiler problem. In your case you might just make all the member public.
Thanks, Robert, but now I get a bunch of warnings, plus link errors. The same is true for my text input archive. Both are attached. I'm hoping it's pretty simple, and that soon I'll understand it too! Here are examples of the warning messages, and the link errors: 1>c:\boost\include\boost-1_33_1\boost\archive\text_oarchive.hpp(75) : warning C4661: 'void boost::archive::text_oarchive_impl<Archive>::save(const std::wstring &)' : no suitable definition provided for explicit template instantiation request 1> with 1> [ 1> Archive=rsg_text_oarchive 1> ] 1> c:\boost\include\boost-1_33_1\boost\archive\text_oarchive.hpp(66) : see declaration of 'boost::archive::text_oarchive_impl<Archive>::save' 1> with 1> [ 1> Archive=rsg_text_oarchive 1> ] -- more warnings for output archive -- 1>c:\boost\include\boost-1_33_1\boost\archive\text_iarchive.hpp(44) : warning C4661: 'boost::archive::text_iarchive_impl<Archive>::text_iarchive_impl(std::istrea m &,unsigned int)' : no suitable definition provided for explicit template instantiation request 1> with 1> [ 1> Archive=rsg_text_iarchive 1> ] 1> c:\boost\include\boost-1_33_1\boost\archive\text_iarchive.hpp(71) : see declaration of 'boost::archive::text_iarchive_impl<Archive>::text_iarchive_impl' 1> with 1> [ 1> Archive=rsg_text_iarchive 1> ] -- more warnings for input archive -- 1>Linking... 1> Creating library C:\Clients\RSG\Projects\version_2\experiments\FileManagerTests\Debug\BinArch iveTest.lib and object C:\Clients\RSG\Projects\version_2\experiments\FileManagerTests\Debug\BinArch iveTest.exp 1>RSGTextTests.obj : error LNK2019: unresolved external symbol "public: __thiscall boost::archive::text_iarchive_impl<class rsg_text_iarchive>::text_iarchive_impl<class rsg_text_iarchive>(class std::basic_istream<char,struct std::char_traits<char> > &,unsigned int)" (??0?$text_iarchive_impl@Vrsg_text_iarchive@@@archive@boost@@QAE@AAV?$basic_ istream@DU?$char_traits@D@std@@@std@@I@Z) referenced in function "public: __thiscall rsg_text_iarchive::rsg_text_iarchive(class std::basic_istream<char,struct std::char_traits<char> > &,unsigned int)" (??0rsg_text_iarchive@@QAE@AAV?$basic_istream@DU?$char_traits@D@std@@@std@@I @Z) 1>RSGTextTests.obj : error LNK2019: unresolved external symbol "public: __thiscall boost::archive::text_oarchive_impl<class rsg_text_oarchive>::text_oarchive_impl<class rsg_text_oarchive>(class std::basic_ostream<char,struct std::char_traits<char> > &,unsigned int)" (??0?$text_oarchive_impl@Vrsg_text_oarchive@@@archive@boost@@QAE@AAV?$basic_ ostream@DU?$char_traits@D@std@@@std@@I@Z) referenced in function "public: __thiscall rsg_text_oarchive_impl<class rsg_text_oarchive>::rsg_text_oarchive_impl<class rsg_text_oarchive>(class std::basic_ostream<char,struct std::char_traits<char> > &,unsigned int)" (??0?$rsg_text_oarchive_impl@Vrsg_text_oarchive@@@@QAE@AAV?$basic_ostream@DU ?$char_traits@D@std@@@std@@I@Z) 1>RSGTextTests.obj : error LNK2019: unresolved external symbol "public: void __thiscall boost::archive::text_iarchive_impl<class rsg_text_iarchive>::load_override(struct boost::archive::class_name_type &,int)" (?load_override@?$text_iarchive_impl@Vrsg_text_iarchive@@@archive@boost@@QAE XAAUclass_name_type@23@H@Z) referenced in function "public: class rsg_text_iarchive & __thiscall boost::archive::detail::interface_iarchive<class rsg_text_iarchive>::operator>><struct boost::archive::class_name_type>(struct boost::archive::class_name_type &)" (??$?5Uclass_name_type@archive@boost@@@?$interface_iarchive@Vrsg_text_iarchi ve@@@detail@archive@boost@@QAEAAVrsg_text_iarchive@@AAUclass_name_type@23@@Z ) 1>RSGTextTests.obj : error LNK2019: unresolved external symbol "public: void __thiscall boost::archive::text_iarchive_impl<class rsg_text_iarchive>::load(class std::basic_string<char,struct std::char_traits<char>,class std::allocator<char> > &)" (?load@?$text_iarchive_impl@Vrsg_text_iarchive@@@archive@boost@@QAEXAAV?$bas ic_string@DU?$char_traits@D@std@@V?$allocator@D@2@@std@@@Z) referenced in function "public: static void __cdecl boost::archive::load_access::load_primitive<class rsg_text_iarchive,class std::basic_string<char,struct std::char_traits<char>,class std::allocator<char> > >(class rsg_text_iarchive &,class std::basic_string<char,struct std::char_traits<char>,class std::allocator<char> > &)" (??$load_primitive@Vrsg_text_iarchive@@V?$basic_string@DU?$char_traits@D@std @@V?$allocator@D@2@@std@@@load_access@archive@boost@@SAXAAVrsg_text_iarchive @@AAV?$basic_string@DU?$char_traits@D@std@@V?$allocator@D@2@@std@@@Z) 1>RSGTextTests.obj : error LNK2019: unresolved external symbol "public: void __thiscall boost::archive::text_oarchive_impl<class rsg_text_oarchive>::save(class std::basic_string<char,struct std::char_traits<char>,class std::allocator<char> > const &)" (?save@?$text_oarchive_impl@Vrsg_text_oarchive@@@archive@boost@@QAEXABV?$bas ic_string@DU?$char_traits@D@std@@V?$allocator@D@2@@std@@@Z) referenced in function "public: static void __cdecl boost::archive::save_access::save_primitive<class rsg_text_oarchive,class std::basic_string<char,struct std::char_traits<char>,class std::allocator<char> > >(class rsg_text_oarchive &,class std::basic_string<char,struct std::char_traits<char>,class std::allocator<char> > const &)" (??$save_primitive@Vrsg_text_oarchive@@V?$basic_string@DU?$char_traits@D@std @@V?$allocator@D@2@@std@@@save_access@archive@boost@@SAXAAVrsg_text_oarchive @@ABV?$basic_string@DU?$char_traits@D@std@@V?$allocator@D@2@@std@@@Z) 1>C:\Clients\RSG\Projects\version_2\experiments\FileManagerTests\Debug\BinAr chiveTest.exe : fatal error LNK1120: 5 unresolved externals 1>Build log was saved at "file://c:\Clients\RSG\Projects\version_2\experiments\FileManagerTests\BinAr chiveTest\Debug\BuildLog.htm" 1>BinArchiveTest - 6 error(s), 128 warning(s) Thanks again! -Bob

You'll need to explicitly instantiate the templated code. Look in the library for test_oarchive.cpp on how to do this. I'm not sure why he MS compiler produces warnings on your code. None of the other compilers I test with do. Including the following in rsg_text_oarchive class- which should not be necessary - diminished the number of warnings to 3 // explicitly forward save for other types to the base class. template<class T> void save(const T & t){ boost::archive::text_oarchive_impl<Archive>::save(t); } Robert Ramey Robert S. Grimes wrote:
So its safe to say its a compiler problem. In your case you might just make all the member public.
Thanks, Robert, but now I get a bunch of warnings, plus link errors. The same is true for my text input archive. Both are attached. I'm hoping it's pretty simple, and that soon I'll understand it too! Here are examples of the warning messages, and the link errors:
1>c:\boost\include\boost-1_33_1\boost\archive\text_oarchive.hpp(75) : warning C4661: 'void boost::archive::text_oarchive_impl<Archive>::save(const std::wstring &)' : no suitable definition provided for explicit template instantiation request 1> with 1> [ 1> Archive=rsg_text_oarchive 1> ] 1> c:\boost\include\boost-1_33_1\boost\archive\text_oarchive.hpp(66)
see declaration of 'boost::archive::text_oarchive_impl<Archive>::save' 1> with 1> [ 1> Archive=rsg_text_oarchive 1> ]
-- more warnings for output archive --
1>c:\boost\include\boost-1_33_1\boost\archive\text_iarchive.hpp(44) : warning C4661: 'boost::archive::text_iarchive_impl<Archive>::text_iarchive_impl(std::istrea m &,unsigned int)' : no suitable definition provided for explicit template instantiation request 1> with 1> [ 1> Archive=rsg_text_iarchive 1> ] 1> c:\boost\include\boost-1_33_1\boost\archive\text_iarchive.hpp(71)
see declaration of 'boost::archive::text_iarchive_impl<Archive>::text_iarchive_impl' 1> with 1> [ 1> Archive=rsg_text_iarchive 1> ]
-- more warnings for input archive --
1>Linking... 1> Creating library C:\Clients\RSG\Projects\version_2\experiments\FileManagerTests\Debug\BinArch iveTest.lib and object C:\Clients\RSG\Projects\version_2\experiments\FileManagerTests\Debug\BinArch iveTest.exp 1>RSGTextTests.obj : error LNK2019: unresolved external symbol "public: __thiscall boost::archive::text_iarchive_impl<class rsg_text_iarchive>::text_iarchive_impl<class rsg_text_iarchive>(class std::basic_istream<char,struct std::char_traits<char> > &,unsigned int)" (??0?$text_iarchive_impl@Vrsg_text_iarchive@@@archive@boost@@QAE@AAV?$basic_ istream@DU?$char_traits@D@std@@@std@@I@Z) referenced in function "public: __thiscall rsg_text_iarchive::rsg_text_iarchive(class std::basic_istream<char,struct std::char_traits<char> > &,unsigned int)" (??0rsg_text_iarchive@@QAE@AAV?$basic_istream@DU?$char_traits@D@std@@@std@@I @Z) 1>RSGTextTests.obj : error LNK2019: unresolved external symbol "public: __thiscall boost::archive::text_oarchive_impl<class rsg_text_oarchive>::text_oarchive_impl<class rsg_text_oarchive>(class std::basic_ostream<char,struct std::char_traits<char> > &,unsigned int)" (??0?$text_oarchive_impl@Vrsg_text_oarchive@@@archive@boost@@QAE@AAV?$basic_ ostream@DU?$char_traits@D@std@@@std@@I@Z) referenced in function "public: __thiscall rsg_text_oarchive_impl<class rsg_text_oarchive>::rsg_text_oarchive_impl<class rsg_text_oarchive>(class std::basic_ostream<char,struct std::char_traits<char> > &,unsigned int)" (??0?$rsg_text_oarchive_impl@Vrsg_text_oarchive@@@@QAE@AAV?$basic_ostream@DU ?$char_traits@D@std@@@std@@I@Z) 1>RSGTextTests.obj : error LNK2019: unresolved external symbol "public: void __thiscall boost::archive::text_iarchive_impl<class rsg_text_iarchive>::load_override(struct boost::archive::class_name_type &,int)" (?load_override@?$text_iarchive_impl@Vrsg_text_iarchive@@@archive@boost@@QAE XAAUclass_name_type@23@H@Z) referenced in function "public: class rsg_text_iarchive & __thiscall boost::archive::detail::interface_iarchive<class rsg_text_iarchive>::operator>><struct boost::archive::class_name_type>(struct boost::archive::class_name_type &)" (??$?5Uclass_name_type@archive@boost@@@?$interface_iarchive@Vrsg_text_iarchi ve@@@detail@archive@boost@@QAEAAVrsg_text_iarchive@@AAUclass_name_type@23@@Z ) 1>RSGTextTests.obj : error LNK2019: unresolved external symbol "public: void __thiscall boost::archive::text_iarchive_impl<class rsg_text_iarchive>::load(class std::basic_string<char,struct std::char_traits<char>,class std::allocator<char> > &)" (?load@?$text_iarchive_impl@Vrsg_text_iarchive@@@archive@boost@@QAEXAAV?$bas ic_string@DU?$char_traits@D@std@@V?$allocator@D@2@@std@@@Z) referenced in function "public: static void __cdecl boost::archive::load_access::load_primitive<class rsg_text_iarchive,class std::basic_string<char,struct std::char_traits<char>,class std::allocator<char> > >(class rsg_text_iarchive &,class std::basic_string<char,struct std::char_traits<char>,class std::allocator<char> > &)" (??$load_primitive@Vrsg_text_iarchive@@V?$basic_string@DU?$char_traits@D@std @@V?$allocator@D@2@@std@@@load_access@archive@boost@@SAXAAVrsg_text_iarchive @@AAV?$basic_string@DU?$char_traits@D@std@@V?$allocator@D@2@@std@@@Z) 1>RSGTextTests.obj : error LNK2019: unresolved external symbol "public: void __thiscall boost::archive::text_oarchive_impl<class rsg_text_oarchive>::save(class std::basic_string<char,struct std::char_traits<char>,class std::allocator<char> > const &)" (?save@?$text_oarchive_impl@Vrsg_text_oarchive@@@archive@boost@@QAEXABV?$bas ic_string@DU?$char_traits@D@std@@V?$allocator@D@2@@std@@@Z) referenced in function "public: static void __cdecl boost::archive::save_access::save_primitive<class rsg_text_oarchive,class std::basic_string<char,struct std::char_traits<char>,class std::allocator<char> > >(class rsg_text_oarchive &,class std::basic_string<char,struct std::char_traits<char>,class std::allocator<char> > const &)" (??$save_primitive@Vrsg_text_oarchive@@V?$basic_string@DU?$char_traits@D@std @@V?$allocator@D@2@@std@@@save_access@archive@boost@@SAXAAVrsg_text_oarchive @@ABV?$basic_string@DU?$char_traits@D@std@@V?$allocator@D@2@@std@@@Z) 1>C:\Clients\RSG\Projects\version_2\experiments\FileManagerTests\Debug\BinAr chiveTest.exe : fatal error LNK1120: 5 unresolved externals 1>Build log was saved at "file://c:\Clients\RSG\Projects\version_2\experiments\FileManagerTests\BinAr chiveTest\Debug\BuildLog.htm" 1>BinArchiveTest - 6 error(s), 128 warning(s)
Thanks again! -Bob
_______________________________________________ Boost-users mailing list Boost-users@lists.boost.org http://lists.boost.org/mailman/listinfo.cgi/boost-users

You'll need to explicitly instantiate the templated code. Look in the library for text_oarchive.cpp on how to do this.
Did it, and after a few stumbles, it works!
Including the following in rsg_text_oarchive class- which should not be necessary - diminished the number of warnings to 3
// explicitly forward save for other types to the base class. template<class T> void save(const T & t){ boost::archive::text_oarchive_impl<Archive>::save(t); }
It actually turns out that this isn't needed. I added at first, then when the other issues were resolved, I thought I'd test whether it was needed. Just to remind you, I'm using VC++ 8.0, so maybe MS has indeed made some progress... ;-) Thanks again!
participants (2)
-
Robert Ramey
-
Robert S. Grimes