fork download
  1. #include <iostream>
  2. #include <memory>
  3.  
  4. struct Base
  5. {
  6. static std::shared_ptr<Base> Create(int args)
  7. {
  8. std::cout << "Base::Create(" << args << ")" << std::endl;
  9. return std::make_shared<Base>();
  10. }
  11. };
  12.  
  13. template<typename T> struct Inherited: T
  14. {
  15. static std::shared_ptr<Base> Create(int args)
  16. {
  17. return T::Create(args);
  18. }
  19. };
  20.  
  21. struct Derived: Inherited<Base>
  22. {
  23. static std::shared_ptr<Base> Create(int args)
  24. {
  25. if (args <= 0)
  26. {
  27. Inherited::Create(args);
  28. }
  29. else
  30. {
  31. std::cout << "Derived::Create(" << args << ")" << std::endl;
  32. return std::shared_ptr<Derived>();
  33. }
  34. }
  35. };
  36.  
  37. int main()
  38. {
  39. Derived::Create(0);
  40. Derived::Create(1);
  41.  
  42. return 0;
  43. }
Success #stdin #stdout 0s 3432KB
stdin
Standard input is empty
stdout
Base::Create(0)
Derived::Create(1)