SabirSazzad

Template

Feb 23rd, 2017
88
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.35 KB | None | 0 0
  1. #include<iostream>
  2. using namespace std;
  3.  
  4. template<class type1, class type2>  class Math{
  5. type1 x;
  6. type1 y;
  7. public:
  8.     Math(type1 xVal, type1 yVal){
  9.         this->x = xVal;
  10.         this->y = yVal;
  11.         }
  12.         type1 sum(){
  13.         return this->x+this->y;
  14.         }
  15.  
  16. };
  17.  
  18.  
  19. int main(){
  20. Math<float, int> m(1, 2.5);
  21. cout<<m.sum();
  22.  
  23. }
Advertisement
Add Comment
Please, Sign In to add comment