fork download
  1. #include <iostream>
  2. #include <cstdlib>
  3.  
  4. template<size_t N> struct S {
  5. S() { std::cout << N << std::endl; }
  6. };
  7. template<size_t N> void create() { new S<N>(); }
  8. void doCreate(size_t n) {
  9. typedef void (*CreateFn)();
  10. CreateFn fn[] = {
  11. create<0>, create<1>, create<2>, create<3>, create<4>
  12. };
  13. fn[n]();
  14. }
  15.  
  16. int main() {
  17. std::srand(time(0));
  18. doCreate(std::rand() % 5);
  19. }
  20.  
Success #stdin #stdout 0.01s 2816KB
stdin
Standard input is empty
stdout
1