www.delorie.com/archives/browse.cgi   search  
Mail Archives: djgpp/1997/04/21/03:30:03

To: djgpp AT delorie DOT com, bf461 AT cleveland DOT freenet DOT edu ("Bryan Murphy")
Subject: Re: Operator == Implementation Question
Date: Mon, 21 Apr 97 07:21:32 GMT
Message-ID: <M.042197.102132.32@Default>
From: cbalciza AT mail DOT cccis DOT ro (Claudiu Balciza)

> 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 strcmp(name,object.name) == 0;
>        };

that's the way you should implement it

> however, would this work fine for me?  As far as I can tell, it would, and
> it would probably work for all objects (not just ones with names).  Or,
> is there a better way?  I'd rather not give each object a unique name if I
> don't have to. 
> 
> operator == (const OBJECT &object)
> {
> return (this == &object);
> };
> 

this one however compares only the addresses of the objects
so it's not going to work except for (s==s)

(it is ok to compare the address of a reference variable
and a pointer)

- Raw text -


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