Robert Ramey wrote:
ray@maya-studio.com wrote:
That's likely something else entirely. We'd have to see more code. Forget my previous post, the exception was due to mixed up ofstream and ifstream...
Just to resume - if I have a list of pointers to the objects (all derived from the same base class) and I'd like to serialize them through a reference, a code like this would be needed:
// List of pointers A a; B b; // Derived from A C c; // Derived from C std::list list; list.push_back(&a); // Base list.push_back(&b); // Derived list.push_back(&c); // Derived ... // Save std::ofstream ofs("c:/test.xml"); boost::archive::xml_oarchive oa(ofs); BOOST_FOREACH(A* pA, list) { if (dynamic_cast(pA)) { B& b = *static_cast(pA); oa & BOOST_SERIALIZATION_NVP(b); } else if (dynamic_cast
(pA)) { C& c = *pA; BOOST_SERIALIZATION_NVP(c); } else { A& a = *pA; BOOST_SERIALIZATION_NVP(a); } } Am I right?
It's not absolutely clear what your object here is. But the following would be equivalent to the above as far as I can tell - and a lot simpler
// Save std::ofstream ofs("c:/test.xml"); boost::archive::xml_oarchive oa(ofs); oa << list;
whoops, I missed the part about skipping the pointer part. So I guess your method above would work - though I'd have to think about it. of course if you had std::list list; there would be nothing to do. Robert Ramey