fork(1) download
  1.  
  2. #include <iostream>
  3. using namespace std;
  4. template <typename Type> class calc{
  5. public:
  6. Type multiply(Type x,Type y);
  7. Type add(Type x,Type y);
  8. };
  9.  
  10. template <typename Type> Type calc<Type>::add(Type x,Type y)
  11. {
  12. return x+y;
  13. }
  14.  
  15. template <typename Type> Type calc<Type>::multiply(Type x,Type y)
  16. {
  17. return x*y;
  18. }
  19. int main(){
  20. calc<int> instance1;
  21. calc<double> instance2;
  22. cout<<instance1.add(2,5)<<endl;
  23. cout<<instance2.multiply(3.0,5.0)<<endl;
  24.  
  25. }
Success #stdin #stdout 0s 3296KB
stdin
Standard input is empty
stdout
7
15