#include<iostream>
#include<memory>
#include<vector>
using namespace std;
struct Test;
void fonction (shared_ptr<Test> test) {
cout << "function" << endl;
}
struct Test : enable_shared_from_this<Test> {
Test() {
cout << "Construction" << endl;
}
~Test () {
cout << "Destruction" << endl;
}
void methode1 () {
cout << "method 1" << endl;
fonction( shared_from_this() );
}
void methode2 () {
cout << "method 2" << endl;
}
};
int main (int argc, char** argv) {
vector<shared_ptr<Test>> tests;
tests.push_back(make_shared<Test>());
Test& t = *tests[0];
t.methode1();
t.methode2();
}
I2luY2x1ZGU8aW9zdHJlYW0+CiNpbmNsdWRlPG1lbW9yeT4KI2luY2x1ZGU8dmVjdG9yPgoKdXNpbmcgbmFtZXNwYWNlIHN0ZDsKIAogc3RydWN0IFRlc3Q7CiAKdm9pZCBmb25jdGlvbiAoc2hhcmVkX3B0cjxUZXN0PiB0ZXN0KSB7Cgljb3V0IDw8ICJmdW5jdGlvbiIgPDwgZW5kbDsKfQogCnN0cnVjdCBUZXN0IDogZW5hYmxlX3NoYXJlZF9mcm9tX3RoaXM8VGVzdD4gewogICAgVGVzdCgpIHsKICAgICAgICBjb3V0IDw8ICJDb25zdHJ1Y3Rpb24iIDw8IGVuZGw7CiAgICB9CiAgICAKICAgIH5UZXN0ICgpIHsKICAgICAgICBjb3V0IDw8ICJEZXN0cnVjdGlvbiIgPDwgZW5kbDsKICAgIH0KIAogICAgdm9pZCBtZXRob2RlMSAoKSB7CiAgICAJY291dCA8PCAibWV0aG9kIDEiIDw8IGVuZGw7CgkJZm9uY3Rpb24oIHNoYXJlZF9mcm9tX3RoaXMoKSApOwoJfQogCgl2b2lkIG1ldGhvZGUyICgpIHsKCQljb3V0IDw8ICJtZXRob2QgMiIgPDwgZW5kbDsKCX0KIAp9OwogCmludCBtYWluIChpbnQgYXJnYywgY2hhcioqIGFyZ3YpIHsKCXZlY3RvcjxzaGFyZWRfcHRyPFRlc3Q+PiB0ZXN0czsKCXRlc3RzLnB1c2hfYmFjayhtYWtlX3NoYXJlZDxUZXN0PigpKTsKCVRlc3QmIHQgPSAqdGVzdHNbMF07Cgl0Lm1ldGhvZGUxKCk7Cgl0Lm1ldGhvZGUyKCk7Cn0=