Article View: comp.std.c++
Article #1158Re: Pointer comparisons
From: Jim Adcock
Date: Thu, 24 Dec 1992 20:08
Date: Thu, 24 Dec 1992 20:08
49 lines
1560 bytes
1560 bytes
In article <1992Dec22.140212.12579@bcrka451.bnr.ca> sjm@bcrki65.bnr.ca (Stuart MacMartin) writes:
|2. Perhaps there is a philosophical argument that might resolve this issue.
| If two objects have the same interface but no state (or constant state), and
| they have the same lifetime, are they in fact the same object? Or, perhaps,
| can they be treated as if they are the same object?
Here's a simple counterexample. b and b.a are clearly different objects.
They have different type, and they respond differently to a given method
call.
HOWEVER, they can both be legally used to initialized an A*, and
in which case the pointers compare equal, and the two different objects
THEN respond the same to a given method.
#include <iostream.h>
class A
{
public:
static void print() { cout << "A\n"; }
};
class B : public A
{
public:
A a;
static void print() { cout << "B\n"; }
};
main()
{
B b;
b.print();
b.a.print();
A* pb = &b;
A* pa = &(b.a);
if (pa == pb)
cout << "addresses match\n";
else
cout << "addresses don't match\n";
pb->print();
pa->print();
return 0;
}
Technical Details
Message-ID:
<1992Dec24.200840.25856@microsoft.com>Path:
arc1-ca.pugleaf.net!sparky!uunet!microsoft!hexnut!jimadReferences:
<1992Dec17.151642.9954@bcrka451.bnr.ca> <1992Dec19.001851.22116@microsoft.com> <1992Dec22.140212.12579@bcrka451.bnr.ca>Show Full Headers
Complete Article Headers
Newsgroups: comp.std.c++ Path: arc1-ca.pugleaf.net!sparky!uunet!microsoft!hexnut!jimad From: jimad@microsoft.com (Jim Adcock) Subject: Re: Pointer comparisons Message-ID: <1992Dec24.200840.25856@microsoft.com> Date: 24 Dec 92 20:08:40 GMT Organization: Microsoft Corporation References: <1992Dec17.151642.9954@bcrka451.bnr.ca> <1992Dec19.001851.22116@microsoft.com> <1992Dec22.140212.12579@bcrka451.bnr.ca> Lines: 49