Untitled

mail@pastecode.io avatar
unknown
plain_text
7 months ago
594 B
1
Indexable
Never
#include <iostream>
using namespace std;

// Class template
template <class T>
class Number {
   private:
    // Variable of type T
    T num;

   public:
    Number(T n1 , T n2);   // constructor

    T getNum(T n1 , T n2) {
        return num1 + num2;
    }
};

int main() {

    // create object with int type
    Number<int> numberInt(7 , 5);

    // create object with double type
    Number<float> numberfloat(7.7 , 5.3);

    cout << "int Number = " << numberInt.getNum() << endl;
    cout << "float Number = " << numberfloat.getNum() << endl;

    return 0;