In some of the homework assignments that I have been given, I never really found a use for templates since regular functions pretty much accomplish the same thing. I know the code below is an overly simplified use of a template, but I couldn't really find a scenario that directly needs templates.
Can someone show me a good example that uses templates. By the way, is using templates even considered good practice for c++?
#include <iostream>
usingnamespace std;
template <class A, class B>
bool falsetrue (A a, B b)
{
if (a==b)
cout << "They are equal" << "\n";
if (a!=b)
cout << "Those numbers aren't equal!" << "\n";
}
int main ()
{
int answer1,answer2;
cout << "Insert two numbers that are equal to each other" << "\n" << "\n";
cout << "Insert the first number:" << "\n";
cin >> answer1;
cout << "Now insert another number" << "\n";
cin >> answer2;
falsetrue (answer1,answer2);
return 0;
}