#include <iostream>
#include <string>
#include <memory>
#include <vector>
struct IFactory {
typedef std::shared_ptr<IFactory> SharedFactory;
virtual std::string Name() { return "IFactory"; }
template<class... Arg>
SharedFactory Dup(const Arg&... A) {
return std::make_shared<std::remove_reference<decltype(*this)>::type>(A...);
}
enum {
ClassA,
ClassB,
};
};
class A :public IFactory {
std::string Name() { return "A"; }
bool Say() { std::cout << "Baw" << std::endl; }
};
class B :public IFactory {
std::string Name() { return "B"; }
bool Say() { std::cout << "Maw" << std::endl; }
};
typedef std::vector<IFactory::SharedFactory> FType;
FType MakeVector() {
FType F = { std::make_shared<A>() ,std::make_shared<B>() };
return F;
}
int main() {
FType F = MakeVector();
auto A = F[0]->Dup();
std::cout << A->Name() << std::endl;
return 0;
}
I2luY2x1ZGUgPGlvc3RyZWFtPgojaW5jbHVkZSA8c3RyaW5nPgojaW5jbHVkZSA8bWVtb3J5PgojaW5jbHVkZSA8dmVjdG9yPgoKc3RydWN0IElGYWN0b3J5IHsKCXR5cGVkZWYgc3RkOjpzaGFyZWRfcHRyPElGYWN0b3J5PiBTaGFyZWRGYWN0b3J5OwoJdmlydHVhbCBzdGQ6OnN0cmluZyBOYW1lKCkgeyByZXR1cm4gIklGYWN0b3J5IjsgfQoJCgl0ZW1wbGF0ZTxjbGFzcy4uLiBBcmc+CglTaGFyZWRGYWN0b3J5IER1cChjb25zdCBBcmcmLi4uIEEpIHsKCQlyZXR1cm4gc3RkOjptYWtlX3NoYXJlZDxzdGQ6OnJlbW92ZV9yZWZlcmVuY2U8ZGVjbHR5cGUoKnRoaXMpPjo6dHlwZT4oQS4uLik7Cgl9CgllbnVtIHsKCQlDbGFzc0EsCgkJQ2xhc3NCLAoJfTsKfTsKCmNsYXNzIEEgOnB1YmxpYyBJRmFjdG9yeSB7CglzdGQ6OnN0cmluZyBOYW1lKCkgeyByZXR1cm4gIkEiOyB9Cglib29sIFNheSgpIHsgc3RkOjpjb3V0IDw8ICJCYXciIDw8IHN0ZDo6ZW5kbDsgfQp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