This is the mail archive of the
gcc-bugs@gcc.gnu.org
mailing list for the GCC project.
g++; operator==
- From: "Markus Bina" <aon dot 912473424 at aon dot at>
- To: <gcc-bugs at gcc dot gnu dot org>
- Date: Tue, 30 Aug 2005 09:59:00 +0200
- Subject: g++; operator==
Hi!
g++ Version: 3.3.5
Linux-distribution: Suse 9.2 and Gentoo 2005.0 on Intel Pentium 4
CFLAGS used to compile gcc: -O2 -pipe
I found the following bug:
bash-output:
xyz@linux:~/test> g++ -o Prog.bin Prog.cpp
Prog.cpp: In function `int main()':
Prog.cpp:32: error: no match for 'operator==' in 'i1 == Int(2)'
Prog.cpp:18: error: candidates are: bool Int::operator==(Int&)
xyz@linux:~/test>
BTW: VC++ and TurboC are able to compile it!
--------------------------------------------------------------------
It is far too difficult to describe the bug, so here is a code snippet to
reproduce the bug:
#include <iostream>
using namespace std;
class Int{
public:
int i;
Int(){
this->i = 0;
}
Int(int i2){
this->i = i2;
}
Int& operator= (Int& i2){
this->i = i2.i;
return *this;
}
bool operator== (Int& i2){
return (this->i == i2.i ? true : false);
}
};
int main(){
Int i1(10);
Int i2(20);
// works
cout << (i1 == i2) << endl;
// does not work; but it should
cout << (i1 == Int(2)) << endl;
return 0;
}