Etiketler
C# PROGRAMMING LANGUAGE CODES, C++ karşılastrma ve mantıksal opreratörlerin aşırı yüklenmesi, mehmet fatih tanış
#include <iostream>
#include <conio.h>
#include <string.h>
using namespace std;
//karşılastrma ve mantıksal operatörlerin aşırı yüklenmesi
// <,> işleçlerini aşırı yükle .
//örnek :a(x1,y1) b(x2,y2)
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);
};
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(1,2);
test b(3,6);
if(a>b)
cout<<“a nin her iki degeri de b den buyuktur”<<endl;
else
cout<<“a nin iki degeride b den buyuk degildir 😉 “<<endl;
if(a<b)
cout<<“a nin iki degeri de b den kucuktur”<<endl;
else
cout<<“a nin iki degeri de b den kucuk degildir”<<endl;
getch();
return 0;
}