Untitled
unknown
plain_text
a year ago
581 B
3
Indexable
Never
#include <iostream> using namespace std; // Class template template <class T> class Number { private: // Variables of type T T num1; T num2; public: Number(T n1, T n2) : num1(n1), num2(n2) {} // Constructor T getNum() { return num1 + num2; } }; int main() { // create object with int type Number<int> numberInt(7, 5); // create object with float type Number<float> numberFloat(7.7, 5.3); cout << "int Number = " << numberInt.getNum() << endl; cout << "float Number = " << numberFloat.getNum() << endl; return 0; }