fork download
  1. #include <iostream>
  2.  
  3. using namespace std;
  4.  
  5. /*int mulByTwo(int v) { cout << "INT\n"; return v*2;}
  6. double mulByTwo(double v) { cout << "DOUBLE\n"; return v*2;}*/
  7.  
  8. template<typename T> T mulByTwo(T v) { return v*2;}
  9.  
  10. int main() {
  11.  
  12. int I = mulByTwo(2); cout << I << endl;
  13. int D = mulByTwo(2.0); cout << D << endl;
  14.  
  15.  
  16. //string S = mulByTwo("it will not compile");
  17.  
  18. return 0;
  19. }
Success #stdin #stdout 0s 3340KB
stdin
Standard input is empty
stdout
4
4