I keep having this issue with this program involving templates. I apologize for posting the entire code, but it's extremely short. The problem I keep having is it claims there's an error in c2872.
driver.cpp
#include <iostream>
#include "pair.h"
using namespace std;
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;
}
Class .cpp file
#include "pair.h"
template <class T>
pair<T>::pair(const T& first, const T& second)
{
f = first;
s = second;
}
template<class T>
T pair<T>::getFirst() const
{
return first;
}
template<class T>
T pair<T>::getSecond() const
{
return second;
}
template<class T>
void pair<T>::setFirst(const T& first, const T& second)
{
T temp = first;
first = second;
second = temp;
}
header file
template <class T>
class pair
{
private:
T f;
T s;
public:
pair(const T&, const T&);
T getFirst() const;
T getSecond() const;
void setFirst(const T&, const T&);
};