fork download
  1. #include <iostream>
  2. #include <vector>
  3.  
  4. using namespace std;
  5.  
  6. enum Types
  7. {
  8. Int,
  9. Double
  10. };
  11.  
  12. //Use struct instead of class for auto-public.
  13. template<Types> struct TypesMap;
  14.  
  15. template<> struct TypesMap<Int>
  16. {
  17. using type = int;
  18. };
  19.  
  20. template<> struct TypesMap<Double>
  21. {
  22. using type = double;
  23. };
  24.  
  25. int main() {
  26. std::vector<void*> Test;
  27.  
  28. Test.push_back(new TypesMap<Int>::type(0.5));
  29. Test.push_back(new TypesMap<Double>::type(0.5));
  30.  
  31. std::cout << *((TypesMap<Int>::type*)Test[0]) << " " << *((TypesMap<Double>::type*)Test[1]);
  32.  
  33. return 0;
  34. }
Success #stdin #stdout 0s 4900KB
stdin
Standard input is empty
stdout
0 0.5