fork download
  1. #include <iostream>
  2.  
  3. template<class Type>
  4. class Other {
  5.  
  6. public:
  7. Type x;
  8. Other(Type y){
  9. x = y;
  10. }
  11. };
  12.  
  13.  
  14.  
  15. void first(const Other<int>& o) {/*One way of specifying the formal parameter*/
  16.  
  17. std::cout << o.x << '\n';
  18. }
  19.  
  20.  
  21.  
  22. template<typename T> void second(const Other<T>& o) {/*Other way of specifyin formal parameter*/
  23. /*Has to be decalred as templated function*/
  24. std::cout << o.x << '\n';
  25. }
  26.  
  27.  
  28. int main(){
  29. Other<int> other(123);/*initializing template class constructor*/
  30. first(other);/*sending templated class as parameters*/
  31. second(other);
  32. }
  33.  
Success #stdin #stdout 0s 3296KB
stdin
Standard input is empty
stdout
123
123