$include_dir="/home/hyper-archives/boost-users/include"; include("$include_dir/msg-header.inc") ?>
From: mik (mirko.cambi_at_[hidden])
Date: 2008-01-21 06:28:24
I'm trying to compile (with VS 2005) a simple example of serialization
(boost 1.34) of a polymorphic class, but I get the following compile error:
basic_xml_oarchive.hpp(83) : error C2027: use of undefined type
'boost::STATIC_ASSERTION_FAILURE<x>'
1>        with
1>        [
1>            x=false
1>        ]
Can you help me? I've read the documentation and I didn't understand the
difference with the example that I found in there.
Here is the source:
-----------------------------------------------------------------
//main.cpp
#include <iostream>
#include <fstream>
#include "boost/archive/xml_oarchive.hpp"
#include "boost/archive/xml_iarchive.hpp"
#include <boost/serialization/base_object.hpp>
#include <boost/serialization/is_abstract.hpp>
#include <boost/serialization/utility.hpp>
class base
{
public:
   base(): _a(0)
   {
   }
   base(double a): _a(a)
   {
   }
   virtual double f() = 0;
protected:
   double _a;
   //Serialitation procedure.
   friend class boost::serialization::access;
   template<class Archive>
   void serialize(Archive & ar, const unsigned int version)
   {
      ar & boost::serialization::make_nvp("a", _a);
   }
};
BOOST_IS_ABSTRACT(base)
class derived: public base
{
public:
   derived(): base(0), _b(0)
   {
   }
   derived(double b): base(1), _b(b)
   {
   }
   double f()
   {
      return _a + _b;
   }
protected:
   double _b;
   //Serialitation procedure.
   friend class boost::serialization::access;
   template<class Archive>
   void serialize(Archive & ar, const unsigned int version)
   {
      ar & boost::serialization::base_object<base>(*this);
      ar & boost::serialization::make_nvp("b", _b);
   }
};
int main()
{
   derived dc(5);
   {
      std::ofstream ofile("test.xml");
      boost::archive::xml_oarchive oa(ofile);
      oa << boost::serialization::make_nvp("test", dc);
   }
   return 0;
}
-----------------------------------------------------------------