fork download
  1. #include <iostream>
  2. using namespace std;
  3.  
  4. struct baseItem {
  5. template <typename T> static T* createItem(int index) {
  6. return new T(index);
  7. }
  8. };
  9. struct Sword : public baseItem {
  10. Sword(int n) { cout << "Creating a sword number " << n << endl; }
  11. };
  12.  
  13.  
  14. int main() {
  15. Sword *s = baseItem::createItem<Sword>(123);
  16. delete s;
  17. return 0;
  18. }
Success #stdin #stdout 0s 3428KB
stdin
Standard input is empty
stdout
Creating a sword number 123