Untitled
unknown
plain_text
2 years ago
594 B
9
Indexable
#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;Editor is loading...