fork(1) download
  1. #include <iostream>
  2. #include <string>
  3. #include <memory>
  4. #include <vector>
  5.  
  6. struct IFactory {
  7. typedef std::shared_ptr<IFactory> SharedFactory;
  8. virtual std::string Name() { return "IFactory"; }
  9. /** /
  10. template<class... Arg>
  11. SharedFactory Dup(const Arg&... A) {
  12. return std::make_shared<decltype(*this)>(A...);
  13. }
  14. /**/
  15. SharedFactory Dup() {
  16.  
  17. using T = decltype(*this);//なんでこれが参照型になるんじゃーーーーーー!!!
  18. T Y=*this;
  19.  
  20. //auto R = std::make_shared<>();
  21. //return R;
  22. return{};
  23. }
  24. };
  25.  
  26. class A :public IFactory {
  27. std::string Name() { return "A"; }
  28. bool Say() { std::cout << "Baw" << std::endl; }
  29. };
  30.  
  31. class B :public IFactory {
  32. std::string Name() { return "B"; }
  33. bool Say() { std::cout << "Maw" << std::endl; }
  34. };
  35.  
  36. typedef std::vector<IFactory::SharedFactory> FType;
  37.  
  38. FType MakeVector() {
  39. FType F = { std::make_shared<A>() ,std::make_shared<B>() };
  40.  
  41. return F;
  42. }
  43.  
  44. int main() {
  45. FType F = MakeVector();
  46.  
  47. auto A = F[0]->Dup();
  48.  
  49. std::cout << A->Name() << std::endl;
  50.  
  51. return 0;
  52. }
Runtime error #stdin #stdout 0s 4308KB
stdin
Standard input is empty
stdout
Standard output is empty