CVector CVector::operator+ (CVector param) で何が行われているのか説明してもらえますか。ドット演算子は temp でどのように機能しますか。object.function() をいつ実行するかは理解していますが、object.object を実行することはどのように理にかなっているのでしょうか。混乱している!!
#include <iostream>
using namespace std;
class CVector {
public:
int x,y;
CVector () {};
CVector (int,int);
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);
}
int main () {
CVector a (3,1);
CVector b (1,2);
CVector c;
c = a + b;
cout << c.x << "," << c.y;
return 0;
}