I am curious about the following code which can execute correctly.
#include <iostream>
using namespace std;
class A
{
public:
A(int a=1, int b=2){
this->a = a;
this->b = b;
}
void print_a(){
cout<<a<<endl;
}
private:
int a;
int b;
};
int main() {
A aa = A(A()); //
aa.print_a();
return 0;
}
The output is 1
which is correct.
I am curious about the mechanism.
The difference between this question is that that question's constructor explicitly accepts an instance.