#include "stdafx.h"
#include <iostream>
usingnamespace std;
class CVector {
public:
int x,y;
CVector () {};
CVector (int,int);
CVector operator - (CVector);
CVector operator --();
CVector operator & (CVector);
};
CVector::CVector (int a, int b) {
x = a;
y = b;
}
CVector CVector::operator- (CVector param) {
CVector temp;
temp.x = x - param.x;
temp.y = y - param.y;
return (temp);
}
CVector CVector::operator --()
{
CVector temp;
temp.x = x--;
temp.y = y--;
return(temp);
}
CVector CVector::operator &(CVector param)
{
return (param);
}
//--------- main -------------------
int main () {
CVector a (3,1);
CVector b (1,2);
CVector c;
CVector *p;
p = new CVector;
c = a - b;
b--;
p = &a;
cout << "p = " << p->x << "," << p->y << endl;
cout << "a = " << a.x << "," << a.y << endl;
cout << "b = " << b.x << "," << b.y << endl;
cout << "c = " << c.x << "," << c.y << endl;
cin.get();
return 0;
}
----------------------------
As you see, there is no arguments passed to the overloaded operator-- but there is for the overloaded operator&.
Is there any way to define the returned value in the operator& function if no arguments passed to it like the example with operator-- ?