[serialization] default constructor problem
Hi,
I am currently experimenting with writing a compiler tool which generates
the code necessary for using boost::serialization. While working on this I
found that I am unable to serialize a variable declaration which is a
reference to a class constructed with the default constructor '()'( ex.
class foo var(); ). I have tried to find an explanation for this in the
examples, documentation and through searching the web without success. Using
pointers it works fine with the
default constructor and I do not see why it should be any different for
references (as references in essence are pointers). Is it possible to
serialize a class constructed using the default constructor using
boost::serialization, and if so how?
Example:
#include <fstream>
// include headers that implement a archive in simple text format
#include
This has nothing to do with seriaization - its a quirk of C++ syntax. Replace
const gps_set s1();
with
const gps_set s1;
and your program will compile and execute as you expect.
The problem is that C++ interprets the formor as declaration of a function named s1 which returns a const gps_set. Trying
to serialize that traps on the notorious "const check" which is just a total coincidence.
The later will create a const gps_set object on the stack which can be serialized with no problem.
To really understand this, you'll have to dig into a little used section of one of your C++ references.
Good Luck,
Robert Ramey
"Andreas Sæbjørnsen"
Thank you very much! After learning this I made an webpage with graphs of
the Abstract Syntax Tree demonstrating an example where a variable
declaration with a constructor call is interpreted as a function
declaration.
http://folk.uio.no/andsebjo/c++/
Thanks
Andreas
On 1/14/06, Sebastian Redl
Robert Ramey wrote:
To really understand this, you'll have to dig into a little used section of one of your C++ references.
For this purpose, I recommend Scott Meyers's Effective STL. "Item 6: Be alert for C++'s most vexing parse." covers this very problem.
Sebastian Redl _______________________________________________ Boost-users mailing list Boost-users@lists.boost.org http://lists.boost.org/mailman/listinfo.cgi/boost-users
participants (3)
-
Andreas Sæbjørnsen
-
Robert Ramey
-
Sebastian Redl