Geri döndürme tipi olan bir operator overloading örneği..
#include <iostream>
#include <string>
#include <stdio.h>
using namespace std;
class Counter
{
private:
int sayac;
public:
Counter():sayac(0)
{}
Counter(int c):sayac(c) //yeni bir constructor var burda
{}
int goster()
{return sayac;}
Counter operator ++()
{
++sayac;
return Counter(sayac); /*bunun constructor a ihtiyaci oldugu icin yukarda 2 constructor kullandim*/
}
};
int main()
{
Counter c1,c2;
cout<< "\n c1="<<c1.goster();
cout<< "\n c2="<<c2.goster();
++c1;
c2=++c1;
cout<< "\n c1="<<c1.goster();
cout<< "\n c2="<<c2.goster()<<endl;
getchar();getchar();
return 0;
}