A PHP Error was encountered

Severity: 8192

Message: str_replace(): Passing null to parameter #3 ($subject) of type array|string is deprecated

Filename: libraries/Filtered_db.php

Line Number: 23

C++ program to demonstrate example of Templates.
Q:

C++ program to demonstrate example of Templates.

0

C++ program to demonstrate example of Templates.

All Answers

need an explanation for this answer? contact us directly to get an explanation for this answer

C++ program - Demonstration of Template in C++ programming language

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

need an explanation for this answer? contact us directly to get an explanation for this answer

total answers (1)

This question belongs to these collections

Similar questions


need a help?


find thousands of online teachers now