I'm confused about the code following, I cannot figure out why Test t
as parameter in calc
and return t
will call Test(Test &t)
? Can anyone help me to make it clear? Thanks a lot!
#include <iostream>
using namespace std;
class Test {
public:
Test(int na, int nb) {
a = na;
b = nb;
}
Test(Test &t) {
a = t.a + 1;
b = t.b + 1;
}
int getValue() {
return a + b;
}
Test calc(Test t) {
return t;
}
private:
int a;
int b;
};
int main() {
Test t(1, 1);
cout << t.calc(t).getValue() << endl;
}