tag:blogger.com,1999:blog-27003286.post5640154716493476377..comments2024-01-24T13:44:36.779+01:00Comments on The Way of C/C++: What is really a POD class?Mats Kindahlhttp://www.blogger.com/profile/07528917029894926261noreply@blogger.comBlogger2125tag:blogger.com,1999:blog-27003286.post-44753295274671854702008-11-06T15:47:00.000+01:002008-11-06T15:47:00.000+01:00You are entirely correct that is does not do the s...You are entirely correct that is does not do the same thing for the cases you mention. Also, the intention of a class is to encapsule data, but by casting the subclass into the base class, the encapsuling can be circumvented, which is not really a good thing.<BR/><BR/>The main problem, however, is that we get a warning for a case that ought to be safe: that of using <B>offsetof()</B> for getting the offset of a member variable in a context where the member variable is accessible. It would be better to not produce a warning for the first case, and hence not force programmers to work around the warning to a case that is not really safe. Note that the compiler should still produce a warning (or even an error) for the cases you give.<BR/><BR/>Also, the main points of the post is to clarify what an <I>aggregate class</I> is and the restrictions on the <B>offsetof()</B> macro.Mats Kindahlhttps://www.blogger.com/profile/07528917029894926261noreply@blogger.comtag:blogger.com,1999:blog-27003286.post-27794547593705754392008-10-03T00:48:00.000+02:002008-10-03T00:48:00.000+02:00This may be stretching the standard's wording a bi...This may be stretching the standard's wording a bit much? While the compiler is silenced, I don't think get_offset() really does what's intended anymore. Consider:<BR/><BR/>[1]<BR/>class Another {<BR/>public:<BR/> int a,b,c;<BR/>};<BR/><BR/>class MyClass : protected Another, protected MyBase {<BR/>public:<BR/> MyClass() { x = 1; y = 2; z = 3; }<BR/><BR/> int get_offset() const {<BR/> return offsetof(MyBase, y);<BR/> }<BR/>};<BR/><BR/>[2] If MyClass had a vtpr.<BR/><BR/>In either case get_offset() would not point to the intended MyClass::y member.Unknownhttps://www.blogger.com/profile/01060334244869056954noreply@blogger.com