Jump to content
  • Advertisement
Sign in to follow this  
ocitalis

Boost serialization

This topic is 3573 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

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
Advertisement
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
Sign in to follow this  

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

We are the game development community.

Whether you are an indie, hobbyist, AAA developer, or just trying to learn, GameDev.net is the place for you to learn, share, and connect with the games industry. Learn more About Us or sign up!

Sign me up!