
That is not a greate problem. The problems start then... The reason of the problem can be follow: one of the operator [](int Index) has two versions, which have only one difference: const OTCValue& and OTCValue&. Maybe the compiler cannot choose the necessary. But now I have another problem: I have such a class, which shouldn't be saved normally (OTCData). The reason for this: this class has a member, which should be rerialized via string, more then that, it cannot be copied (OTCDataID and OTCDataHeaderID). So I've tried to do following: #include <boost/serialization/tracking.hpp> #include <boost/serialization/split_member.hpp> namespace DataManagement { class OTCData : public IOTCData { friend class boost::serialization::access; template<class Archive> void save(Archive & ar, const unsigned int version) const { const std::string own_id=m_own_id->save_to_string(); ar & own_id; const std::string header_id=m_header_id->save_to_string(); ar & header_id; ar & m_rows; ar & m_cols; } template<class Archive> void load(Archive & ar, const unsigned int version) { std::string own_id; std::string header_id; ar & own_id; m_own_id->load_from_string(own_id); ar & header_id; m_header_id->load_from_string(header_id); ar & rows; ar & m_cols; } BOOST_SERIALIZATION_SPLIT_MEMBER(); std::auto_ptr<OTCDataID> m_own_id; std::auto_ptr<OTCDataHeaderID> m_header_id; std::vector<OTCRow> m_rows; int m_cols; // shouldn't be serialized const IOTCDataHeader * m_header; }; } Then function to save instance of OTCData: namespace DataManagement{ class DataController { void save_otcdata(const OTCData&data)const; }; void DataManagement::DataController::save_otcdata(const OTCData& data) const { std::string file_name=set_file_name(data); std::ofstream ofs(file_name.c_str()); boost::archive::text_oarchive oa(ofs); oa << data; // Here I have very long compiler error messages // which are very like the messages by trying to save nonconstant object } } I have no idea any more. I save only constants and the compilation fails! Thanks to all! -------- Original-Nachricht -------- Datum: Thu, 3 Aug 2006 08:14:41 -0700 Von: "Robert Ramey" <ramey@rrsd.com> An: boost-users@lists.boost.org Betreff: Re: [Boost-users] Subject: Serialization, text_Xarchive Why doesn\'t work?
Is it possible that m_value is uninitialized? It is a known problem that many compilers can can write uninitialized floating/double values to a text stream and then cannot read them. This topic is currently being discussd on the developer's list - as it arises all the time.
Take a look a test_serial.txt with a text editor. What does it look like?
Robert Ramey
tkachenkok@gmx.de wrote:
I've tried to write my first application with Boost.Serialization library.
Here is the part of code, where the boost::text_iarchive throws an exception "boost::archive::archive_exception" "what(): stream error":
[code] enum Origin { UNKNOWN=0, MEASURED, AVERAGE };
class OTCValue { friend class boost::serialization::access; template<class Archive> void serialize(Archive & ar, const unsigned int version) { ar & m_value; ar & m_orig; } double m_value; Origin m_orig; ... }; ... const OTCValue val1=(*loaded.second.begin())->get_row(0)[0]; { std::ofstream ofs("test_serial.txt"); boost::archive::text_oarchive oa(ofs); oa << val1; } OTCValue val; { std::ifstream ifs("test_serial.txt"); boost::archive::text_iarchive ia(ifs); ia >> val; // here is this exceptions thrown } ... [/code]
And here is a little bit different code, which works great:
[code] enum Origin { UNKNOWN=0, MEASURED, AVERAGE };
class OTCValue { friend class boost::serialization::access; template<class Archive> void serialize(Archive & ar, const unsigned int version) { ar & m_value; ar & m_orig; } double m_value; Origin m_orig; ... }; ... const OTCValue val1(5.5, MEASURED); { std::ofstream ofs("test_serial.txt"); boost::archive::text_oarchive oa(ofs); oa << val1; } OTCValue val; { std::ifstream ifs("test_serial.txt"); boost::archive::text_iarchive ia(ifs); ia >> val; } ... [/code]
What is the problem? The construction (*loaded.second.begin())->get_row(0)[0] returns an OTCValue .
I have compiled the boost-1.33.1 from the sources (www.boost.org). The project I've made is under KDevelop 3.2.2 (initially consol "Hello World" application)
Operating System: SuSe Linux 10.0 Compiler: gcc version 4.0.2
I hope, that I've gave enouph information. If not, ask what aou need, you are welcome.
Best regards, and thanks to all!
_______________________________________________ Boost-users mailing list Boost-users@lists.boost.org http://lists.boost.org/mailman/listinfo.cgi/boost-users
-- Echte DSL-Flatrate dauerhaft für 0,- Euro*. Nur noch kurze Zeit! "Feel free" mit GMX DSL: http://www.gmx.net/de/go/dsl