Like the functionality i want to achieve is as under: but it will not work. How can i achieve the same functionality?
Code:
# include <iostream.h>
# include <conio.h>
template <class T>
class Test
{
T a;
public:
void set()
{
cin>>a;
}
void display()
{
cout<<"A is"<<a<<endl;
}
};
int main()
{
int choice;
cin>>choice;
if(choice == 1)
{
Test<int> obj;
}
else if(choice ==2)
{
Test<char> obj;
}
else
{
Test<float> obj;
}
obj.set();
obj.display();
return 0;
}
Comment