#include <iostream>
using namespace std;
class A {
public:
int first;
int last;
A(int x = 0, int y = 0):first(x), last(y){}
A(A&a) { cout << "c ctor \n"; }
};
ostream& operator<<(ostream& os, A b) {
os << "first:" << b.first << " last:" << b.last << endl;
return os;
}
istream& operator>>(istream& is, A a) {
is >> a.first >> a.last;
return is;
}
int main()
{
A i;
cout << "enter first and last: \n";
cin >> i;
cout << i;
system("pause");
return 0;
}
A a is a new A object in the >> overload, and if we enter 6 4 into it, the program will remember it in the << overload function, and print what we entered into it. Can someone explain why? Thanks.