Boost logo

Boost Users :

From: Oliver Mutz (mutz_at_[hidden])
Date: 2006-04-03 04:39:28


Try changing the return type of foo() to const double.
For the reason see the ratinale page in the serialization documentation.

Oliver

Drumheller, Michael wrote:
> The test program below (under boost 1_33, vc71) compiles fine, unless
> I change the "#if 1" to "#if 0", in which case it produces this:
> error C2679: binary '<<': no operator found which takes a right-hand
> operand of type 'double' (or there is no acceptable conversion)
>
> Can anyone explain why that should happen? A double is a double--why
> should '<<' care whether the rhs comes from funcall a variable?
>
> Note: The test program is clearly a nonsense program (in real life
> the role of foo() is played by some public (get-accessor) on klass--a
> very common pattern when doing a non-intrusive serialization). But I
> did not want to cloud the issue--I wanted to emphasize that the bug,
> if it is a bug, seems to have nothing to with klass.
>
> Thank you.
>
> Michael Drumheller
> -----------------------------------------------------------------begin--
> -------------------------------------------------------------
> #include <fstream>
> #include <boost/archive/text_oarchive.hpp>
> #include <boost/serialization/split_free.hpp>
> class klass {};
> double foo() { return 3.1416; }
> namespace boost { namespace serialization {
> template<class Archive>
> void save(Archive &ar, const klass & b, const unsigned int
> ver)
> {
> #if 1
> double x=foo();
> ar << x;
> #else
> ar << foo();
> #endif
> }
> template<class Archive>
> void load(Archive &ar, klass & b, const unsigned int ver){}//N/A
> for this demo }}
> BOOST_SERIALIZATION_SPLIT_FREE(klass);
> void out(const char *testfile, const klass & c)
> {
> std::ofstream ofs(testfile);
> boost::archive::text_oarchive oa(ofs);
> oa << c;
> }
> ----------------------------------------------------------------end-----
> -----------------------------------------------------------------
> Michael Drumheller
> Boeing Phantom Works
> Mathematics and Engineering Analysis
> 425.865.3520 michael.drumheller_at_[hidden]
>
> _______________________________________________
> Boost-users mailing list
> Boost-users_at_[hidden]
> http://lists.boost.org/mailman/listinfo.cgi/boost-users


Boost-users list run by williamkempf at hotmail.com, kalb at libertysoft.com, bjorn.karlsson at readsoft.com, gregod at cs.rpi.edu, wekempf at cox.net