Topic: operator == taking references


Author: Greg Wright <gregory@slmd.com>
Date: 1998/06/12
Raw View
mash2@my-dejanews.com wrote:
>
> I may be being brain dead here, but I have the following problem:
>
> I've delcared a list of class CFoo, as follows
>
> list<CFoo> FooList;
>
> I'm calling remove() on the list, so I need to declare an operator == in class
> CFoo. Here's how I've done it:
>
> bool operator==(CFoo x)
> {
>     bool fRet = false;
>     // do the comparison
>     return fRet;
> }
>
> This compiles and works (under VC5). Of course, what I really want to do take
> a reference to CFoo in the operator==. The problem is that I get a compiler
> error when done this way: "binary '==' : no operator defined which takes a
> left-hand operand of type 'class CFoo' (or there is no acceptable
> conversion)"
>
> Can anyone see what I've done wrong?
[SNIP!]

Did you try:

   bool operator==(const CFoo& x) const

greg.
--
        _________     USPA: A-20947     Gregory Wright
        __  ____/__________________ _   gregory@slmd.com
        _  / __ __  ___/  _ \_  __ `/   gregory@halcyon.com
        / /_/ / _  /   /  __/  /_/ /    Spacelabs Medical Inc.
 PDGA#  \____/  /_/    \___/_\__, /     Intesys Division.
 13380                      /____/      (206)867-7327


[ comp.std.c++ is moderated.  To submit articles, try just posting with ]
[ your news-reader.  If that fails, use mailto:std-c++@ncar.ucar.edu    ]
[              --- Please see the FAQ before posting. ---               ]
[ FAQ: http://reality.sgi.com/austern_mti/std-c++/faq.html              ]






Author: mash2@my-dejanews.com
Date: 1998/06/11
Raw View
I may be being brain dead here, but I have the following problem:

I've delcared a list of class CFoo, as follows

list<CFoo> FooList;

I'm calling remove() on the list, so I need to declare an operator == in class
CFoo. Here's how I've done it:

bool operator==(CFoo x)
{
    bool fRet = false;
    // do the comparison
    return fRet;
}

This compiles and works (under VC5). Of course, what I really want to do take
a reference to CFoo in the operator==. The problem is that I get a compiler
error when done this way: "binary '==' : no operator defined which takes a
left-hand operand of type 'class CFoo' (or there is no acceptable
conversion)"

Can anyone see what I've done wrong?

TIA,
manish

-----== Posted via Deja News, The Leader in Internet Discussion ==-----
http://www.dejanews.com/   Now offering spam-free web-based newsreading
---
[ comp.std.c++ is moderated.  To submit articles, try just posting with ]
[ your news-reader.  If that fails, use mailto:std-c++@ncar.ucar.edu    ]
[              --- Please see the FAQ before posting. ---               ]
[ FAQ: http://reality.sgi.com/austern_mti/std-c++/faq.html              ]





Author: Alexander Myles Jonas <ajonas@zip.com.au>
Date: 1998/06/12
Raw View
mash2@my-dejanews.com wrote:

> I've delcared a list of class CFoo, as follows
>
> list<CFoo> FooList;
>
> I'm calling remove() on the list, so I need to declare an operator == in class
> CFoo. Here's how I've done it:
>
> bool operator==(CFoo x)
> {
>     bool fRet = false;
>     // do the comparison
>     return fRet;
> }
>
> This compiles and works (under VC5). Of course, what I really want to do take
> a reference to CFoo in the operator==. The problem is that I get a compiler
> error when done this way: "binary '==' : no operator defined which takes a
> left-hand operand of type 'class CFoo' (or there is no acceptable
> conversion)"
>
> Can anyone see what I've done wrong?
>

Try using bool operator==(const CFoo& x) {...}




[ comp.std.c++ is moderated.  To submit articles, try just posting with ]
[ your news-reader.  If that fails, use mailto:std-c++@ncar.ucar.edu    ]
[              --- Please see the FAQ before posting. ---               ]
[ FAQ: http://reality.sgi.com/austern_mti/std-c++/faq.html              ]