2

I am reading the xml file and storing into boost::property_tree::ptree pt(object).

I am trying to serialize this ptree object using the method serialize() defined in ptree_serialization.hpp

boost::property_tree::serialize(ar,pt,1);

When i use above code i get the error as;

boost/serialization/collections_save_imp.hpp:64:9: error: no match for ‘operator<<’ in ‘ar << boost::serialization::make_nvp(const char*, T&) [with T = const std::pair<const std::basic_string<char>, boost::property_tree::basic_ptree<std::basic_string<char>, std::basic_string<char> > >]((* &((boost::iterator_facade<boost::property_tree::basic_ptree<std::basic_string<char>, std::basic_string<char> >::const_iterator, std::pair<const std::basic_string<char>, boost::property_tree::basic_ptree<std::basic_string<char>, std::basic_string<char> > >, boost::bidirectional_traversal_tag, const std::pair<const std::basic_string<char>, boost::property_tree::basic_ptree<std::basic_string<char>, std::basic_string<char> > >&, int>*)(& boost::operator++ [with I = boost::property_tree::basic_ptree<std::basic_string<char>, std::basic_string<char> >::const_iterator, V = std::pair<const std::basic_string<char>, boost::property_tree::basic_ptree<std::basic_string<char>, std::basic_string<char> > >, TC = boost::bidirectional_traversal_tag, R = const std::pair<const std::basic_string<char>, boost::property_tree::basic_ptree<std::basic_string<char>, std::basic_string<char> > >&, D = int, typename boost::detail::postfix_increment_result<I, V, R, TC>::type = boost::property_tree::basic_ptree<std::basic_string<char>, std::basic_string<char> >::const_iterator]((*(boost::iterator_facade<boost::property_tree::basic_ptree<std::basic_string<char>, std::basic_string<char> >::const_iterator, std::pair<const std::basic_string<char>, boost::property_tree::basic_ptree<std::basic_string<char>, std::basic_string<char> > >, boost::bidirectional_traversal_tag, const std::pair<const std::basic_string<char>, boost::property_tree::basic_ptree<std::basic_string<char>, std::basic_string<char> > >&, int>*)(& it)), 0)))->boost::iterator_facade<I, V, TC, R, D>::operator* [with Derived = boost::property_tree::basic_ptree<std::basic_string<char>, std::basic_string<char> >::const_iterator, Value = std::pair<const std::basic_string<char>, boost::property_tree::basic_ptree<std::basic_string<char>, std::basic_string<char> > >, CategoryOrTraversal = boost::bidirectional_traversal_tag, Reference = const std::pair<const std::basic_string<char>, boost::property_tree::basic_ptree<std::basic_string<char>, std::basic_string<char> > >&, Difference = int, boost::iterator_facade<I, V, TC, R, D>::reference = const std::pair<const std::basic_string<char>, boost::property_tree::basic_ptree<std::basic_string<char>, std::basic_string<char> > >&]()))’

Could you please let me know if i am doing something wrong. Could you please let me know if we can serialize the xml parsed property ptree object.

sehe
  • 374,641
  • 47
  • 450
  • 633
harshini
  • 59
  • 1
  • 4
  • could you tell us how you defined `ar` and `pt`? – Arashium Jan 21 '15 at 11:30
  • ar can be either iarchive or oarchive object. pt is declared as boost::property_tree::ptree pt; – harshini Jan 21 '15 at 11:31
  • i am not expert in this area. `boost::property_tree::ptree pt(object)` seems lack of template: ``. i think `serialize` needs a `basic_ptree` type for second argument according to its source code: http://www.boost.org/doc/libs/1_42_0/boost/property_tree/ptree_serialization.hpp , Also see: http://codereview.stackexchange.com/questions/1818/ . see if they help – Arashium Jan 21 '15 at 12:01

1 Answers1

2

You should use the archive interface as intended: doc

ar << pt;

or

ar >> pt;

The version is as configured using BOOST_CLASS_VERSION(Type, version) but that's in the implementation of Property Tree

Also remember to

#include <boost/property_tree/ptree_serialization.hpp>
sehe
  • 374,641
  • 47
  • 450
  • 633
  • i am getting below error when used ar << pt error: request for member ‘serialize’ in ‘val’, which is of non-class type ‘boost::property_tree::basic_ptree, std::basic_string >*’ – harshini Jan 21 '15 at 13:17
  • It says you're serializing a pointer. (This might be normal). I _think_ you are missing the include (see the answer text). You ***could*** try `ar << *pt` though – sehe Jan 21 '15 at 13:19
  • I included #include and still i am getting below error error: ‘struct boost::property_tree::basic_ptree, std::basic_string >’ has no member named ‘serialize’ – harshini Jan 22 '15 at 04:40