I am having problems with figuring out how to use templates to take a class and move a char value. I have tried to overload the = operator, but ran into probelms because I don't quite understant how that function works. I run into compile errors on lines 72 and 79. Any help will be appreciated.
There is no reason for askType to be a template. In all cases you want it to take a string input and produce a char. You just don't use the type anywhere.
Do you realize that when you call askType <Animal> ("lion");, the compiler generates a function
1 2 3 4 5 6 7 8 9
Animal askType(Animal x)
{
char typeOfThing;
cout << endl << "Is this animal or vegetable?" << endl;
cout << " " << x << endl;
cout << "Enter A or V" << endl;
cin >> typeOfThing;
return(typeOfThing);
}
your Animal class dont have implicitly constructor but its explicity !!! and cannot convert implicity
"lion" to Animal !! Secondly, in askType you cant return char type instead T type as Animal Type you must return animal type or change type of return function