Etiketler

, ,

#include <iostream>
#include <conio.h>
#include <string.h>
using namespace std;
//karşılastrma ve mantıksal opreratörlerin aşırı yüklenmesi
//&& ve == işleçlerini aşırı yükleyelim
class test{
int x,y;
public:
test(){
x=0;
y=0;
}

test(int a,int b){
x=a;
y=b;
}
//tür operator ,'<‘ için, ( sinifadi ,nesne adi)
int operator==(test ob);
int operator&&(test ob);

};
//a(x,y) ve b(ob.x,ob.y)
int test ::operator==(test ob){
return x == ob.x && y==ob.y;
}
int test ::operator&&(test ob){
return (x && ob.x) && (y &&ob.y);
}

main(){
test a(6,6);
test b(3,6);

if(a==b)
cout<<“a esit b”<<endl;
else
cout<<“a ve b farkli “<<endl;
if(a&&b)
cout<<“true”;
else
cout<<“false”;

getch();
return 0;

}