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
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started