Let’s consider the example
#include <iostream> using namespace std; template <typename TYPE> class Numbers { private: TYPE x, y; public: //constructor Numbers(const TYPE a, const TYPE b) : x(a), y(b) {} TYPE getX() { return x; } TYPE getY() { return y; } }; int main() { Numbers<float> NUM1(100, 200); cout<<"Values with integer numbers: "; cout << NUM1.getX() << ", " << NUM1.getY() << endl; Numbers<float> NUM2(100.20, 150.69); cout<<"Values with float numbers: "; cout << NUM2.getX() << ", " << NUM2.getY() << endl; return 0; }
Values with integer numbers: 100, 200 Values with float numbers: 100.2, 150.69
total answers (1)
start bookmarking useful questions and collections and save it into your own study-lists, login now to start creating your own collections.
C++ program - Demonstration of Template in C++ programming language
Let’s consider the example
Values with integer numbers: 100, 200 Values with float numbers: 100.2, 150.69need an explanation for this answer? contact us directly to get an explanation for this answer