• Source
    1. #include<iostream>
    2. using namespace std;
    3. template <class dt>
    4. class numbers{
    5. public:
    6. dt no1 , no2 , sum ;
    7. public:
    8. numbers(dt a , dt b)
    9. {
    10. no1 = a;
    11. no2 = b;
    12. }
    13.  
    14. dt add (){
    15. sum = no1 + no2 ;
    16. }
    17. dt display(){
    18. cout<<"The sum is :"<<sum<<endl;;
    19. }
    20. };
    21.  
    22. int main(){
    23. cout<<"Passing integer :"<<endl;
    24. numbers <int> first(3,4);
    25. first.add();
    26. first.display();
    27. cout<<"Passing float :"<<endl;
    28. numbers <float> second(3.14,70.54);
    29. second.add();
    30. second.display();
    31. return 0 ;
    32.  
    33. }