More than one operator "==" matches these operands

Intrebari despre limbajul C++, standardul C++, STL, OOP in C++ sau alte subiecte nelegate de VisualC++
Post Reply
Raduku077
Junior
Junior
Posts: 20
Joined: 09 Jan 2014, 15:41
Judet: Iaşi

More than one operator "==" matches these operands

Post by Raduku077 » 07 Apr 2014, 23:18

Eroarea : More than one operator "==" matches these operands .

Code: Select all

int operator==(rational r1, rational r2) {
	// Returneaza 1 daca r1 == r2 , zero altfel.
	if(r1.numarator == 0) {
		if(r2.numarator == 0) return 1;
		else return 0;
	}
	if(r2.numarator == 0) {
		if(r1.numarator == 0) return 1;
		else return 0;
	}

	rational t1 = r1;
	rational t2 = r2;
	t1.simplifica();
	t2.simplifica();
	return t1.numarator == t2.numarator && t1.numitor == t2.numitor;
}

void main() {
...
if(a == 0 && b == 0) {
			printf("Ecuatie nedeterminata .\n");
			continue;
		}
		if(a == 0) {
			printf("Ecuatia nu are solutie.\n");
			continue;
		}
...
Imi dau seama de ce apare eroarea dar cum o pot rezolva ?
( Visual Studio 2010 Express )
Va multumesc !



Viorel
Microsoft MVP
Microsoft MVP
Posts: 293
Joined: 13 Jul 2007, 12:26

Re: More than one operator "==" matches these operands

Post by Viorel » 08 Apr 2014, 08:26

Cred că e nevoie de mai multe detalii. Vezi dacă există o fereastră Output (în meniul View) cu alte amănunte. Depinde și de constructorii clasei.

Vezi dacă merge cînd mai adaugi un operator:

Code: Select all

bool operator == (rational r, int i)
{
    return ( r == rational(i, 1) ) != 0;
}
Dacă nu, atunci oferă mai multe detalii sau atașează un scurt proiect.

Raduku077
Junior
Junior
Posts: 20
Joined: 09 Jan 2014, 15:41
Judet: Iaşi

Re: More than one operator "==" matches these operands

Post by Raduku077 » 08 Apr 2014, 22:02

Problema a disparut. A aparut acum problema cu operatorul " * " dar acum stiu cum s-o rezolv.
Va multumesc !

User avatar
Marius Bancila
Fondator
Fondator
Posts: 2344
Joined: 11 Jul 2007, 11:45
Judet: Timiş
Location: Timisoara
Contact:

Re: More than one operator "==" matches these operands

Post by Marius Bancila » 09 Apr 2014, 09:56

Atentie, operator tau == pentru clasa rational returneaza int in loc de bool, desi ultimul return din functie e o expresie booleana.

Code: Select all

return t1.numarator == t2.numarator && t1.numitor == t2.numitor;
Eu as defini operatorii asa:

Code: Select all

bool operator==(rational const & r1, rational const &r2);
bool operator==(rational const & r, int const i);
Marius Bancila
Fondator Codexpert, Microsoft MVP VC++
Site personal | Blog

Post Reply