#include <iostream>
#include <vector>
#include <memory>
class Base { public: Base() { std::cout << "Base-Ctor" << std::endl; }};
std::vector<Base*> elements;
template <typename T>
class A : public Base
{
public:
A()
{
std::cout << "A-Ctor begin" << std::endl;
elements.push_back(&(T::get()));
std::cout << "A-Ctor end" << std::endl;
}
};
class B : public A<B>
{
public:
B() { std::cout << "B-Ctor" << std::endl; }
static B& get()
{
std::cout << "create static" << std::endl;
static B b;
std::cout << "return static" << std::endl;
return b;
}
};
int main(void)
{
B b;
std::cout << elements.size() << std::endl;
}
I2luY2x1ZGUgPGlvc3RyZWFtPgojaW5jbHVkZSA8dmVjdG9yPgojaW5jbHVkZSA8bWVtb3J5PgoKY2xhc3MgQmFzZSB7IHB1YmxpYzogQmFzZSgpIHsgc3RkOjpjb3V0IDw8ICJCYXNlLUN0b3IiIDw8IHN0ZDo6ZW5kbDsgfX07CnN0ZDo6dmVjdG9yPEJhc2UqPiBlbGVtZW50czsKCnRlbXBsYXRlIDx0eXBlbmFtZSBUPgpjbGFzcyBBIDogcHVibGljIEJhc2UKewpwdWJsaWM6CiAgICBBKCkKICAgIHsKICAgICAgICBzdGQ6OmNvdXQgPDwgIkEtQ3RvciBiZWdpbiIgPDwgc3RkOjplbmRsOwogICAgICAgIGVsZW1lbnRzLnB1c2hfYmFjaygmKFQ6OmdldCgpKSk7CiAgICAgICAgc3RkOjpjb3V0IDw8ICJBLUN0b3IgZW5kIiA8PCBzdGQ6OmVuZGw7CiAgICB9Cn07CmNsYXNzIEIgOiBwdWJsaWMgQTxCPgp7CnB1YmxpYzoKICAgIEIoKSB7IHN0ZDo6Y291dCA8PCAiQi1DdG9yIiA8PCBzdGQ6OmVuZGw7IH0KICAgIHN0YXRpYyBCJiBnZXQoKSAKICAgIHsgCiAgICAgICAgc3RkOjpjb3V0IDw8ICJjcmVhdGUgc3RhdGljIiA8PCBzdGQ6OmVuZGw7IAogICAgICAgIHN0YXRpYyBCIGI7IAogICAgICAgIHN0ZDo6Y291dCA8PCAicmV0dXJuIHN0YXRpYyIgPDwgc3RkOjplbmRsOyAKICAgICAgICByZXR1cm4gYjsgCiAgICB9Cn07CgppbnQgbWFpbih2b2lkKQp7CiAgICBCIGI7CgogICAgc3RkOjpjb3V0IDw8IGVsZW1lbnRzLnNpemUoKSA8PCBzdGQ6OmVuZGw7Cn0=