I have two constructors in C++, and one constructor calls the other one in order not to duplicate initialization logic.
#include <iostream>
#include <memory>
using namespace std;
class A
{
int x;
int y;
public:
A(int x)
{
cout << this << endl;
this->x = x;
}
A()
{
cout << this << endl;
A(20);
}
...
};
What is interesting is A() calls A(int), but the this pointer points to different address. Why is this? Or is this g++ bug?
int main(int argc, char *argv[]) {
A* a = new A();
}
0x7fa8dbc009d0 <-- from A()
0x7fff67d660d0 <-- from A(int)