delorie.com/archives/browse.cgi   search  
Mail Archives: djgpp/1997/04/16/01:05:07

Message-Id: <199704160452.AAA03266@hcst.net>
From: "Bryan Murphy" <bf461 AT cleveland DOT freenet DOT edu>
To: <djgpp AT delorie DOT com>
Subject: Re: Operator == Implementation Question
Date: Wed, 16 Apr 1997 00:49:01 -0400
MIME-Version: 1.0

>> I have a question about operator== for classes.  What is the best
method
>> for implementing that?   Currently, I have a string called name, and
each
>> object has an individual name.  I just use that for comparison. 
>>
>> operator == (const OBJECT &object)
>> {
>> return (this == &object);
>> };
>>
>>

>This last one won't work.  (You can't take the address of a reference
>variable.)  Here is an example program of what I think you want to do:

Why not?  That seems a little illogical to me, afterall, refernces ARE 
referring to a specific location in memory.

> bool operator==(const mystringtype& a)
> {
> return (strcmp(this->string, a.string) == 0);
> }
>}; // end of class mystringtype

Actually, that is exactly what it does, and exactly what I don't want it
to do.  I don't want to give every object in memory an Identifier or a 
specific name.  There has to be a way to check to see if their equal
w/o doing something like that.  The whole reason is that I want multiple
copies of the exact same object to be stored in a list, yet I want to be
able to tell when I'm referring to one object specifically, and not the
others.  I'd rather not use a unique ID or name, because as I said before,
I want them to be exact copies.


- Raw text -


  webmaster     delorie software   privacy  
  Copyright © 2019   by DJ Delorie     Updated Jul 2019