Sign in to follow this  
ocitalis

Boost serialization

Recommended Posts

I am trying to add boost serialization to my C++/CLI project to allow data to be saved. I have created 2 simple classes, Population and Command to test if saving is possible. [I have installed boost 1.36.0, and have compiled the serialization library with bjam. I created a project with the first code example from the serialization tutorial and it does work properly.] I have tried everything to squash the flood of errors (18 usually) that result from compilation attempts. Is managed code completely incompatible with the serialization library? Any help is greatly appreciated. //Population.h #pragma once #include "boost\archive\text_iarchive.hpp" #include "boost\archive\text_oarchive.hpp" ref class Population { public: template <class Archive> void serialize(Archive &ar, const unsigned int version) { friend class boost::serialization::access; ar &m_iMembers; ar &m_iEpochs; ar &m_iCurrentEpoch; } public: Population() { m_iEpochs = 1; m_iMembers = 1; m_iCurrentEpoch = 1; } Population(int iEpochs, int iMembers); Population(Population %Old); Population(int iEpo, int iMem, int iCur): m_iEpochs(iEpo), m_iMembers(iMem), m_iCurrentEpoch(iCur) {} public: int m_iMembers; int m_iEpochs; int m_iCurrentEpoch; }; /////Population.cpp #include "StdAfx.h" #include "Population.h" #include <fstream> #include <iostream> #include <boost/archive/text_oarchive.hpp> #include <boost/archive/text_iarchive.hpp> Population::Population(int iEpochs, int iMembers) { m_iEpochs = iEpochs; m_iMembers = iMembers; m_iCurrentEpoch = 1; } Population::Population(Population %Old) { m_iEpochs = Old.m_iEpochs; m_iMembers = Old.m_iMembers; m_iCurrentEpoch = Old.m_iCurrentEpoch; } //Command.h #pragma once #include "Population.h" #include <fstream> ref class Command { public: Command(void); void SavePop(); }; //Command.cpp #include "StdAfx.h" #include "Command.h" Command::Command(void) { } void Command::SavePop() { Population pop1(1,2,3); std::ofstream ofs("PopSave"); boost::archive::text_oarchive oa(ofs); oa << pop1;//commenting this line out allows no error compilation } The errors I am getting: 1>Command.cpp 1>.\Command.cpp(15) : error C2893: Failed to specialize function template 'boost::archive::text_oarchive &boost::archive::detail::interface_oarchive<Archive>::operator <<(T &)' 1> with 1> [ 1> Archive=boost::archive::text_oarchive 1> ] 1> With the following template arguments: 1> 'Population' 1>.\Command.cpp(15) : error C2784: 'std::basic_ostream<_Elem,_Traits> &boost::operator <<(std::basic_ostream<_Elem,_Traits> &,const boost::shared_ptr<Y> &)' : could not deduce template argument for 'std::basic_ostream<_Elem,_Traits> &' from 'boost::archive::text_oarchive' 1> C:\Program Files\boost\boost_1_36_0\boost/shared_ptr.hpp(627) : see declaration of 'boost::operator <<' 1>.\Command.cpp(15) : error C2784: 'std::basic_ostream<_Elem,_Traits> &boost::operator <<(std::basic_ostream<_Elem,_Traits> &,const boost::shared_ptr<Y> &)' : could not deduce template argument for 'std::basic_ostream<_Elem,_Traits> &' from 'boost::archive::text_oarchive' 1> C:\Program Files\boost\boost_1_36_0\boost/shared_ptr.hpp(627) : see declaration of 'boost::operator <<' 1>.\Command.cpp(15) : error C2784: 'std::basic_ostream<_Elem,_Traits> &boost::operator <<(std::basic_ostream<_Elem,_Traits> &,const boost::shared_ptr<Y> &)' : could not deduce template argument for 'std::basic_ostream<_Elem,_Traits> &' from 'boost::archive::text_oarchive' 1> C:\Program Files\boost\boost_1_36_0\boost/shared_ptr.hpp(627) : see declaration of 'boost::operator <<' 1>.\Command.cpp(15) : error C2784: 'std::basic_ostream<_Elem,_Traits> &boost::operator <<(std::basic_ostream<_Elem,_Traits> &,const boost::shared_ptr<Y> &)' : could not deduce template argument for 'std::basic_ostream<_Elem,_Traits> &' from 'boost::archive::text_oarchive' 1> C:\Program Files\boost\boost_1_36_0\boost/shared_ptr.hpp(627) : see declaration of 'boost::operator <<' 1>.\Command.cpp(15) : error C2784: 'std::basic_ostream<_Elem,_Traits> &boost::operator <<(std::basic_ostream<_Elem,_Traits> &,const boost::shared_ptr<Y> &)' : could not deduce template argument for 'std::basic_ostream<_Elem,_Traits> &' from 'boost::archive::text_oarchive' 1> C:\Program Files\boost\boost_1_36_0\boost/shared_ptr.hpp(627) : see declaration of 'boost::operator <<' 1>.\Command.cpp(15) : error C2784: 'std::basic_ostream<_Elem,_Traits> &boost::operator <<(std::basic_ostream<_Elem,_Traits> &,const boost::shared_ptr<Y> &)' : could not deduce template argument for 'std::basic_ostream<_Elem,_Traits> &' from 'boost::archive::text_oarchive' 1> C:\Program Files\boost\boost_1_36_0\boost/shared_ptr.hpp(627) : see declaration of 'boost::operator <<' 1>.\Command.cpp(15) : error C2784: 'std::basic_ostream<_Elem,_Traits> &boost::operator <<(std::basic_ostream<_Elem,_Traits> &,const boost::shared_ptr<Y> &)' : could not deduce template argument for 'std::basic_ostream<_Elem,_Traits> &' from 'boost::archive::text_oarchive' 1> C:\Program Files\boost\boost_1_36_0\boost/shared_ptr.hpp(627) : see declaration of 'boost::operator <<' 1>.\Command.cpp(15) : error C2784: 'const E &boost::operator <<(const E &,const boost::error_info<Tag,T> &)' : could not deduce template argument for 'const boost::error_info<Tag,T> &' from 'Population' 1> C:\Program Files\boost\boost_1_36_0\boost/exception/exception.hpp(40) : see declaration of 'boost::operator <<' 1>.\Command.cpp(15) : error C2784: 'const E &boost::operator <<(const E &,const boost::error_info<Tag,T> &)' : could not deduce template argument for 'const boost::error_info<Tag,T> &' from 'Population' 1> C:\Program Files\boost\boost_1_36_0\boost/exception/exception.hpp(40) : see declaration of 'boost::operator <<' 1>.\Command.cpp(15) : error C2784: 'std::basic_ostream<_Elem,_Traits> &boost::operator <<(std::basic_ostream<_Elem,_Traits> &,const boost::intrusive_ptr<Y> &)' : could not deduce template argument for 'std::basic_ostream<_Elem,_Traits> &' from 'boost::archive::text_oarchive' 1> C:\Program Files\boost\boost_1_36_0\boost/intrusive_ptr.hpp(292) : see declaration of 'boost::operator <<' 1>.\Command.cpp(15) : error C2784: 'std::basic_ostream<_Elem,_Traits> &boost::operator <<(std::basic_ostream<_Elem,_Traits> &,const boost::intrusive_ptr<Y> &)' : could not deduce template argument for 'std::basic_ostream<_Elem,_Traits> &' from 'boost::archive::text_oarchive' 1> C:\Program Files\boost\boost_1_36_0\boost/intrusive_ptr.hpp(292) : see declaration of 'boost::operator <<' 1>.\Command.cpp(15) : error C2784: 'std::basic_ostream<_Elem,_Traits> &boost::operator <<(std::basic_ostream<_Elem,_Traits> &,const boost::intrusive_ptr<Y> &)' : could not deduce template argument for 'std::basic_ostream<_Elem,_Traits> &' from 'boost::archive::text_oarchive' 1> C:\Program Files\boost\boost_1_36_0\boost/intrusive_ptr.hpp(292) : see declaration of 'boost::operator <<' 1>.\Command.cpp(15) : error C2784: 'std::basic_ostream<_Elem,_Traits> &boost::operator <<(std::basic_ostream<_Elem,_Traits> &,const boost::intrusive_ptr<Y> &)' : could not deduce template argument for 'std::basic_ostream<_Elem,_Traits> &' from 'boost::archive::text_oarchive' 1> C:\Program Files\boost\boost_1_36_0\boost/intrusive_ptr.hpp(292) : see declaration of 'boost::operator <<' 1>.\Command.cpp(15) : error C2784: 'std::basic_ostream<_Elem,_Traits> &boost::operator <<(std::basic_ostream<_Elem,_Traits> &,const boost::intrusive_ptr<Y> &)' : could not deduce template argument for 'std::basic_ostream<_Elem,_Traits> &' from 'boost::archive::text_oarchive' 1> C:\Program Files\boost\boost_1_36_0\boost/intrusive_ptr.hpp(292) : see declaration of 'boost::operator <<' 1>.\Command.cpp(15) : error C2784: 'std::basic_ostream<_Elem,_Traits> &boost::operator <<(std::basic_ostream<_Elem,_Traits> &,const boost::intrusive_ptr<Y> &)' : could not deduce template argument for 'std::basic_ostream<_Elem,_Traits> &' from 'boost::archive::text_oarchive' 1> C:\Program Files\boost\boost_1_36_0\boost/intrusive_ptr.hpp(292) : see declaration of 'boost::operator <<' 1>.\Command.cpp(15) : error C2784: 'std::basic_ostream<_Elem,_Traits> &boost::operator <<(std::basic_ostream<_Elem,_Traits> &,const boost::intrusive_ptr<Y> &)' : could not deduce template argument for 'std::basic_ostream<_Elem,_Traits> &' from 'boost::archive::text_oarchive' 1> C:\Program Files\boost\boost_1_36_0\boost/intrusive_ptr.hpp(292) : see declaration of 'boost::operator <<' 1>.\Command.cpp(15) : error C2676: binary '<<' : 'boost::archive::text_oarchive' does not define this operator or a conversion to a type acceptable to the predefined operator

Share this post


Link to post
Share on other sites
I can't comment on the C++/CLI issue (if there is one) since I don't use managed code but there is another problem here.

In Command::SavePos() try making pop1 const. boost::serialize wants const values (see this for the reason.)

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

Sign in to follow this