Question: In C++ 1. Create a Template Class named Obj. The class has one private variable, x, which can be of any type. Create a member

In C++

1. Create a Template Class named Obj. The class has one private variable, x, which can be of any type. Create a member function of the class that returns square of the number x. In addition, implement functions that can return the value of x and set value of x. Your class should have constructor and destructor.

2. Create a Template Function that returns the sqrt of any generic class M that has means to return the value of its data variable.

3. In the main function, create an object of class Obj on the heap and initialize it with non-zero data. Print its square. Create an array of 5 objects of class Obj on the stack, initialize them with non zero data and print their sqrts using the template function.

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!