Article View: comp.std.c++
Article #1305Re: Must derived class reserve space for an empty base class?
From: Lars Nyman
Date: Fri, 18 Dec 1992 18:47
Date: Fri, 18 Dec 1992 18:47
40 lines
1321 bytes
1321 bytes
jimad@microsoft.com (Jim Adcock) writes:
|class A {};
|
|class B : public A
|{
|public:
| A a;
|};
|
|main()
|{
| B b;
| A* p1;
| A* p2;
|
| p1 = &b;
| p2 = &(b.a);
|
| if (p1 == p2)
| printf("equal %lX %lX\n", (long)p1, (long)p2);
| else
| printf("unequal %lX %LX\n", (long)p1, (long)p2);
|
| return 0;
|}
ARM p74: "Two pointers to the same object compare equal".
ARM p163: "An object of a class consists of a (possibly empty) sequence of
members".
I don't know if ARM defines what "same object" means.
But, it seems to me a member is a different (i.e. not the same) object than
the "enclosing object".
E.g. using the example above, 'b' is not the same object as 'b.a'.
Therefore, according to ARM p74-75, the pointer comparison in the example
above 'p1 == p2' (in effect '((A*) &b) == &b.a') is implementation dependent.
Atleast according to my reading of the ARM as it stands today...
Technical Details
Message-ID:
<18184@autodesk.COM>Path:
arc1-ca.pugleaf.net!sparky!uunet!nntp1.radiomail.net!fernwood!autodesk!larsnReferences:
<1992Dec16.202800.3398@microsoft.com>Show Full Headers
Complete Article Headers
Path: arc1-ca.pugleaf.net!sparky!uunet!nntp1.radiomail.net!fernwood!autodesk!larsn From: larsn@Autodesk.COM (Lars Nyman) Newsgroups: comp.std.c++ Subject: Re: Must derived class reserve space for an empty base class? Message-ID: <18184@autodesk.COM> Date: 18 Dec 92 18:47:33 GMT References: <1992Dec16.202800.3398@microsoft.com> Organization: Autodesk Inc., Sausalito CA, USA Lines: 40