On Jun 25, 11:14 pm, "Victor Bazarov" <v.Abaza...@comAcast.netwrote:
kenkahn wrote:
[...]
My question is what if instead I have
xxx *A_ptr = new xxx;
xxx *B_ptr = new xxx;
How do I define the operator override to work on object pointers
instead of by reference.
if (A_Ptr == B_ptr) {}
You cannot redefine operators for built-in types, and pointers are
built-in types.
The important point, of course, is that the above expression
already has a defined semantics. With very few exceptions
(unary operator&), you can't change defined semantics.
Do
if (A_Ptr && B_Ptr && *A_Ptr == *B_ptr) {}
if ( A_Ptr == NULL
? B_Ptr == NULL
: B_Ptr != NULL && *A_Ptr == *B_Ptr ) {}
:-)
Most of the time, I think I'd go with a function call.
(PS: I'm not saying that your response was wrong. Since he
didn't say what the semantics were supposed to be, we don't
know. Most of the time I'm dealing with pointers, the built-in
semantics are what I want.)
--
James Kanze (GABI Software) email:ja*********@gmail.com
Conseils en informatique orientée objet/
Beratung in objektorientierter Datenverarbeitung
9 place Sémard, 78210 St.-Cyr-l'École, France, +33 (0)1 30 23 00 34