Re: Address of two different objects of the same type
In your example the object of class B (b) comtains only one member - the
object of type A (a). So the address of the object b is the same as the
address of its first (and only) member a.
Vladimir Grigoriev
"Matthias Hofmann" <hofmann@anvil-soft.com> wrote in message
news:61e1mbF1ubi5eU1@mid.individual.net...
Hello everybody!
As far as I understand the C++ standard, pointers to two different objects
of the same type cannot appear at the same address. Now please take a look
at the following code:
#include <iostream>
struct A {};
struct B : public A { A a; };
int main()
{
B b;
A* p = &b;
std::cout << p << std::endl;
std::cout << &b.a << std::endl;
return 0;
}
The output I am getting on Visual C++ 2005 Express Edition is:
0012F3D8
0012F3D8
Is this a bug? After all, we are dealing with two different objects of the
same type, so how can they appear at the same address?
--
Matthias Hofmann
Anvil-Soft, CEO
http://www.anvil-soft.com - The Creators of Toilet Tycoon
http://www.anvil-soft.de - Die Macher des Klomanagers