Doing my homework, got stuck on the template function part. I have the following main()
in my .cpp
file:
int main()
{
Pair<char> letters('a', 'd');
cout << "\nThe first letter is: " << letters.getFirst();
cout << "\nThe second letter is: " << letters.getSecond();
cout << endl;
system("pause");
return 0;
}
I need to use template
to make the class
exchageable, and here is what I have in the .h
file:
template <class T>
class Pair
{
private:
T letters;
public:
T getFirst();
T getSecond();
};
now, in my VS, it says both getFrist()
and getSecond()
are not found. How am I supposed to pass T as a class
in template
?