[Boost.Serialization] Serializing "abstract" classes
Dear all, I'm using Boost 1.45... I've read Boost.Serialization docs so many times and can't understand why my testcase is not working as expected. According to the following three links, we need to address serialization of derived classes with "abstract" base class by using boost macros: http://www.boost.org/doc/libs/1_47_0/libs/serialization/doc/traits.html#expo... http://www.boost.org/doc/libs/1_47_0/libs/serialization/doc/special.html#exp... http://www.boost.org/doc/libs/1_47_0/libs/serialization/doc/traits.html#abst... I did my testcase ( http://codepad.org/6ETp1Ac0 ) completely based on the demo: http://www.boost.org/doc/libs/1_47_0/libs/serialization/example/demo.cpp Compiling and running shows that the derived class archive contains just the base class data members. What is happening? How can i solve this problem? I really appreciate any help, Júlio.
Júlio Hoffimann wrote:
Dear all,
I'm using Boost 1.45...
I've read Boost.Serialization docs so many times and can't understand why my testcase is not working as expected. According to the following three links, we need to address serialization of derived classes with "abstract" base class by using boost macros:
http://www.boost.org/doc/libs/1_47_0/libs/serialization/doc/traits.html#expo...
http://www.boost.org/doc/libs/1_47_0/libs/serialization/doc/special.html#exp...
http://www.boost.org/doc/libs/1_47_0/libs/serialization/doc/traits.html#abst...
I did my testcase ( http://codepad.org/6ETp1Ac0 ) completely based on the demo: http://www.boost.org/doc/libs/1_47_0/libs/serialization/example/demo.cpp
Have you tried to build adn run the demo as it is? Does it work? Robert Ramey
Compiling and running shows that the derived class archive contains just the base class data members. What is happening? How can i solve this problem?
One obvious problem is that the base class is not abstract. To be abstract, a base class must have atleast one virtual function in the form virtual my_function() = 0; The ASSUME_ABSTRACT macro doesn't mark it abstract to the compiler - it marks it abstract to the boost type-traites system. I know it's quirky and unclear - but I see no way to make it bullet proof. I'm sort of surprised/disappointed that this doesn't give a compile time warning. What compiler do you use? Robert Ramey
I really appreciate any help, Júlio.
Thank you for reply Robert,
Yes, i've compiled the code using GCC 4.5. Now i see the warning you
mentioned:
warning:40: type qualifiers ignored on function return type
I've used BOOST_SERIALIZATION_ASSUME_ABSTRACT because the library
documentation is a little confusing with the "abstract class" term. But note
that even commenting out the macro, the problem remains. What is the warning
about on line 40? I'm missing something trivial? :-)
I've also tried to misplace the BOOST_EXPORT_CLASS macro among the source
lines, but without success. Do you have any hint in what is happening?
Appreciate your help,
Júlio.
2011/8/5 Robert Ramey
** Júlio Hoffimann wrote:
Dear all,
I'm using Boost 1.45...
I've read Boost.Serialization docs so many times and can't understand why my testcase is not working as expected. According to the following three links, we need to address serialization of derived classes with "abstract" base class by using boost macros:
http://www.boost.org/doc/libs/1_47_0/libs/serialization/doc/traits.html#expo...
http://www.boost.org/doc/libs/1_47_0/libs/serialization/doc/special.html#exp...
http://www.boost.org/doc/libs/1_47_0/libs/serialization/doc/traits.html#abst...
I did my testcase ( http://codepad.org/6ETp1Ac0 ) completely based on the demo: http://www.boost.org/doc/libs/1_47_0/libs/serialization/example/demo.cpp
Have you tried to build adn run the demo as it is? Does it work?
Robert Ramey
Compiling and running shows that the derived class archive contains just the base class data members. What is happening? How can i solve this problem?
One obvious problem is that the base class is not abstract. To be abstract, a base class must have atleast one virtual function in the form
virtual my_function() = 0;
The ASSUME_ABSTRACT macro doesn't mark it abstract to the compiler - it marks it abstract to the boost type-traites system. I know it's quirky and unclear - but I see no way to make it bullet proof.
I'm sort of surprised/disappointed that this doesn't give a compile time warning. What compiler do you use?
Robert Ramey
I really appreciate any help, Júlio.
_______________________________________________ Boost-users mailing list Boost-users@lists.boost.org http://lists.boost.org/mailman/listinfo.cgi/boost-users
Just correcting another mistake mine, the warning is not on line 40 as i
said. It's in export.hpp 134:40.
Do you have any hint Robert? What could i do to fix this? I heard
Boost.Serialization changed dramatically from 1.45 to actual versions. I
just don't want to upgrade right now because i'm the middle of another job.
Regards,
Júlio.
2011/8/5 Júlio Hoffimann
Thank you for reply Robert,
Yes, i've compiled the code using GCC 4.5. Now i see the warning you mentioned:
warning:40: type qualifiers ignored on function return type
I've used BOOST_SERIALIZATION_ASSUME_ABSTRACT because the library documentation is a little confusing with the "abstract class" term. But note that even commenting out the macro, the problem remains. What is the warning about on line 40? I'm missing something trivial? :-)
I've also tried to misplace the BOOST_EXPORT_CLASS macro among the source lines, but without success. Do you have any hint in what is happening?
Appreciate your help, Júlio.
2011/8/5 Robert Ramey
** Júlio Hoffimann wrote:
Dear all,
I'm using Boost 1.45...
I've read Boost.Serialization docs so many times and can't understand why my testcase is not working as expected. According to the following three links, we need to address serialization of derived classes with "abstract" base class by using boost macros:
http://www.boost.org/doc/libs/1_47_0/libs/serialization/doc/traits.html#expo...
http://www.boost.org/doc/libs/1_47_0/libs/serialization/doc/special.html#exp...
http://www.boost.org/doc/libs/1_47_0/libs/serialization/doc/traits.html#abst...
I did my testcase ( http://codepad.org/6ETp1Ac0 ) completely based on the demo:
http://www.boost.org/doc/libs/1_47_0/libs/serialization/example/demo.cpp
Have you tried to build adn run the demo as it is? Does it work?
Robert Ramey
Compiling and running shows that the derived class archive contains just the base class data members. What is happening? How can i solve this problem?
One obvious problem is that the base class is not abstract. To be abstract, a base class must have atleast one virtual function in the form
virtual my_function() = 0;
The ASSUME_ABSTRACT macro doesn't mark it abstract to the compiler - it marks it abstract to the boost type-traites system. I know it's quirky and unclear - but I see no way to make it bullet proof.
I'm sort of surprised/disappointed that this doesn't give a compile time warning. What compiler do you use?
Robert Ramey
I really appreciate any help, Júlio.
_______________________________________________ Boost-users mailing list Boost-users@lists.boost.org http://lists.boost.org/mailman/listinfo.cgi/boost-users
Júlio Hoffimann wrote:
Just correcting another mistake mine, the warning is not on line 40 as i said. It's in export.hpp 134:40.
That's where it's detected. It's caused somehere else - see below.
Do you have any hint Robert? What could i do to fix this? I heard Boost.Serialization changed dramatically from 1.45 to actual versions. I just don't want to upgrade right now because i'm the middle of another job.
One obvious problem is that the base class is not abstract. To be abstract, a base class must have atleast one virtual function in the form virtual my_function() = 0; The ASSUME_ABSTRACT macro doesn't mark it abstract to the compiler - it marks it abstract to the boost type-traites system. I know it's quirky and unclear - but I see no way to make it bullet proof. I'm sort of surprised/disappointed that this doesn't give a compile time warning. What compiler do you use? Robert Ramey
Yes, but why?
../libs/boost/include/boost/serialization/export.hpp:134:40: warning: type
qualifiers ignored on function return type
main.cpp:83:5: warning: unused parameter ‘argc’
main.cpp:83:5: warning: unused parameter ‘argv’
Can you reproduce the error in your Boost version?
2011/8/5 Robert Ramey
Júlio Hoffimann wrote:
Just correcting another mistake mine, the warning is not on line 40 as i said. It's in export.hpp 134:40.
That's where it's detected. It's caused somehere else - see below.
Do you have any hint Robert? What could i do to fix this? I heard Boost.Serialization changed dramatically from 1.45 to actual versions. I just don't want to upgrade right now because i'm the middle of another job.
One obvious problem is that the base class is not abstract. To be abstract, a base class must have atleast one virtual function in the form
virtual my_function() = 0;
The ASSUME_ABSTRACT macro doesn't mark it abstract to the compiler - it marks it abstract to the boost type-traites system. I know it's quirky and unclear - but I see no way to make it bullet proof.
I'm sort of surprised/disappointed that this doesn't give a compile time warning. What compiler do you use?
Robert Ramey
_______________________________________________ Boost-users mailing list Boost-users@lists.boost.org http://lists.boost.org/mailman/listinfo.cgi/boost-users
I think this is one of the tricky things that turns C++ a complex
language! The *this object is in fact of type B, even inside a virtual
function because the B& operator*(B*) is called. I was using
typeid(*this).name() to debug, without knowing it's virtual behavior.
The solution is simple to remove the "*" from "*this", serialization is fine
through the pointers! About the warning, it has no relation with this
problem, occurs because i'm using an old version of Boost.
Thank you Robert for your attention, don't need to waste time thinking on
this. :-)
Living and learning C++,
Júlio.
2011/8/5 Júlio Hoffimann
Yes, but why?
../libs/boost/include/boost/serialization/export.hpp:134:40: warning: type qualifiers ignored on function return type main.cpp:83:5: warning: unused parameter ‘argc’ main.cpp:83:5: warning: unused parameter ‘argv’
Can you reproduce the error in your Boost version?
2011/8/5 Robert Ramey
Júlio Hoffimann wrote:
Just correcting another mistake mine, the warning is not on line 40 as i said. It's in export.hpp 134:40.
That's where it's detected. It's caused somehere else - see below.
Do you have any hint Robert? What could i do to fix this? I heard Boost.Serialization changed dramatically from 1.45 to actual versions. I just don't want to upgrade right now because i'm the middle of another job.
One obvious problem is that the base class is not abstract. To be abstract, a base class must have atleast one virtual function in the form
virtual my_function() = 0;
The ASSUME_ABSTRACT macro doesn't mark it abstract to the compiler - it marks it abstract to the boost type-traites system. I know it's quirky and unclear - but I see no way to make it bullet proof.
I'm sort of surprised/disappointed that this doesn't give a compile time warning. What compiler do you use?
Robert Ramey
_______________________________________________ Boost-users mailing list Boost-users@lists.boost.org http://lists.boost.org/mailman/listinfo.cgi/boost-users
participants (2)
-
Júlio Hoffimann
-
Robert Ramey