#include <iostream>
using namespace std;
class Test
{
public:
Test(){cout << "test con" << endl;}
~Test(){cout << "test des" << endl;}
};
class Filesystem
{
public:
Filesystem(){std::cout << "fs con!" << endl;}
~Filesystem(){cout << "fs des!" << endl;}
int b;
int a;
Test t;
};
Filesystem& getFs()
{
static Filesystem fs;
return fs;
}
int main()
{
Filesystem fs1 = getFs();
fs1.a += 1;
std::cout << "a1=" << fs1.a << " addr1=" << &fs1 << " a1=" << &fs1.a << endl;
Filesystem fs2 = getFs();
//cout << fs1.a << endl;
fs2.a += 2;
std::cout << "a2=" << fs2.a << " addr2=" << &fs2 << " a1=" << &fs1.a << endl;
fs1 = getFs();
//cout << fs1.a << endl;
fs1.a += 3;
std::cout << "a1=" << fs1.a << " addr1=" << &fs1 << " a1=" << &fs1.a << endl;
}
test con
fs con!
a1=1 addr1=0x7fffffffddf0 a1=0x7fffffffddf4
a2=2 addr2=0x7fffffffdde0 a1=0x7fffffffddf4
a1=3 addr1=0x7fffffffddf0 a1=0x7fffffffddf4
fs des!
test des
fs des!
test des
fs des!
test des