I have the following code:
#include <iostream>
using namespace std;
class Test {
public:
static Test& get() {
static Test testSing;
return testSing;
}
};
int main() {
Test a = Test::get();
Test b = Test::get();
cout << &a << endl;
cout << &b << endl;
}
I thought that a
and b
should have the same address, since I thought they should be constructed only once. However, I get different memmory addresses in this test.
Is there something trivial that I am missing? Shouldn't they have the same address?