Code:
#include <iostream>
using namespace std;
class broj
{
private:
int a;
int b;
public:
broj (int aa, int bb)
{
a = aa; b = bb;
}
//-----------------Prefiksni oblik--------------------------------
broj& operator++ ()
{
++a;
++b;
return *this;
}
friend broj& operator-- (broj& b)
{
--b.a;
--b.b;
return b;
}
//-----------------Postfiksni oblik-------------------------------
broj operator--(int f)
{
broj a = *this;
a--;
b--;
return a;
}
friend broj operator++(broj& b, int f)
{
broj a = b;
b.a++;
b.b++;
return a;
}
//----------------------------------------------------------------
friend ostream& operator<< (ostream& dat, const broj& b)
{
dat << '(' << b.a << ',' << b.b << ')' << endl;
}
};
main()
{
broj a(2,2);
cout << a-- << a;
system("pause");
}
#include <iostream>
using namespace std;
class broj
{
private:
int a;
int b;
public:
broj (int aa, int bb)
{
a = aa; b = bb;
}
//-----------------Prefiksni oblik--------------------------------
broj& operator++ ()
{
++a;
++b;
return *this;
}
friend broj& operator-- (broj& b)
{
--b.a;
--b.b;
return b;
}
//-----------------Postfiksni oblik-------------------------------
broj operator--(int f)
{
broj a = *this;
a--;
b--;
return a;
}
friend broj operator++(broj& b, int f)
{
broj a = b;
b.a++;
b.b++;
return a;
}
//----------------------------------------------------------------
friend ostream& operator<< (ostream& dat, const broj& b)
{
dat << '(' << b.a << ',' << b.b << ')' << endl;
}
};
main()
{
broj a(2,2);
cout << a-- << a;
system("pause");
}
Da li neko zna zasto mi ne radi postfiksni operator --?