Hey guys,
Here's my code:
#include <iostream>
using namespace std ;
template<class T>
class Pair
{
public:
Pair ( ) ;
Pair (T v1 , T v2 ) ;
void setFirst(T newV ) ;
void setSecond(T newV ) ;
T getFirst() const ;
T getSecond() const ;
private:
T first ;
T second ;
} ;
template<class T>
Pair<T>::Pair(T v1 , T v2 ) : first(v1) , second(v2)
{ }
template<class T>
void Pair<T>::setFirst(T newV)
{ first = newV ; }
template<class T>
void Pair<T>::setSecond(T newV)
{ second = newV ; }
template<class T>
T Pair<T>::getFirst() const
{
return first ;
}
template<class T>
T Pair<T>::getSecond() const
{
return second ;
}
template<class T>
T addUp(const Pair<T>& thePair) ;
typedef Pair<double> PairOfDbl ;
typedef Pair<int> PairOfInt ;
int main ( )
{
PairOfDbl pair1 ;
PairOfInt pair2 ;
pair1.setFirst ( 10.3 ) ;
pair1.setSecond ( 20.72 ) ;
pair2.setFirst ( 15 ) ;
pair2.setSecond ( 35 ) ;
cout << addUp ( pair1 ) << endl ;
cout << addUp ( pair2 ) << endl ;
return 0 ;
}
template<class T>
T addUp(const Pair<T>& thePair)
{
return (thePair.getFirst() + thePair.getSecond());
}
I'm getting about 5 LINK errors. What am I missing? =\