Boost logo

Boost :

From: Matthias Troyer (troyer_at_[hidden])
Date: 2004-04-22 12:43:25


Robert, I'm still fighting with implementing archives to see how I
could use your library with our 10 years worth of simulation data. I
think it should be doable but am trying to implement a very simple
archive. Modifying the trivial archive example I thought that the
following should work:

#include <boost/archive/common_oarchive.hpp>
#include <boost/serialization/vector.hpp>
#include <boost/serialization/string.hpp>
#include <iostream>

class odump_archive
  : public boost::archive::common_oarchive<odump_archive>
{
public:
   odump_archive(std::ostream& dump) : os(dump) {}
   template<class T>
   odump_archive& operator<<(const T & t)
   { boost::serialization::save(* This(), t); return * This(); }

   // archives are expected to support this function
   void save_binary(const void *address, size_t count)
   {
   // do something later
}

private:
   std::ostream& os;
   friend class boost::archive::save_access;
   template<class T> void save(const T & t) { os << t;}
};

int main()
{
   odump_archive dump(std::cout);
   std::vector<int> v(4,5);
   std::string s("Hello, world!");
   dump << v << s;
}

But this gives me the following compile time errors using g++ 3.1 on
MacOS X:

test.C: In member function `odump_archive&
odump_archive::operator<<(const T&)
    [with T = std::vector<int, std::allocator<int> >]':
test.C:33: instantiated from here
test.C:14: error: no matching function for call to
`save(odump_archive&, const
    std::vector<int, std::allocator<int> >&)'
test.C: In member function `odump_archive&
odump_archive::operator<<(const T&)
    [with T = std::string]':
test.C:33: instantiated from here
test.C:14: error: no matching function for call to
`save(odump_archive&, const
    std::basic_string<char, std::char_traits<char>, std::allocator<char>
>&)'

Can you help me by telling me what I'm doing incorrectly?

Matthias


Boost list run by bdawes at acm.org, gregod at cs.rpi.edu, cpdaniel at pacbell.net, john at johnmaddock.co.uk