Hi,
So I am currently working on a homework assignment for my data structures class, basically C++, and I am having some troubles converting a working c++ program to use a template.
#include <iostream>
using namespace std;
/* -------------------------------------------------------------------------- */
/* */
/* SECTION: DECLARATIONS */
/* */
/* -------------------------------------------------------------------------- */
template<class T>
class TClass
{
public:
// constructor
TClass();
//destructor
~TClass();
//to compute the minimum of two integers
int min(int,int);
//to compute the minimum of two floats
float min(float,float);
//to compute the minimum of two characters
char min(char,char);
//to compute the maximum of two integers
int max(int,int);
//to compute the maximum of two floats
float max(float,float);
//to compute the maximum of two characters
char max(char,char);
//to compute whether two integers are equal or not
bool isEqual(int,int);
//to compute whether two floats are equal or not
bool isEqual(float,float);
//to compute whether two characters are equal or not
bool isEqual(char,char);
};//end of class TClass
#include "TClass.cpp"
and
/* ------------------------------------------------------------------------- */
/* */
/* SECTION: IMPLEMENTATIONS */
/* */
/* -------------------------------------------------------------------------- */
/**
* This is the default constructor method for the class TClass.
*/
template<class T>
TClass<T>::TClass(){}
/*----------------------------------------------------------------------------*/
/**
* This is the destructor method for the class TClass.
*/
template<class T>
TClass<T>::~TClass(){}
/*----------------------------------------------------------------------------*/
/**
* This overloaded method computes the minimum of two integers.
*/
template<class T>
int TClass<T>::min(int a,int b)
{
return (a < b)?a:b ;
}
/*----------------------------------------------------------------------------*/
/**
* This overloaded method computes the minimum of two floating point numbers.
*/
template<class T>
float TClass<T>::min(float a,float b)
{
return (a < b)?a:b ;
}
/*----------------------------------------------------------------------------*/
/**
* This overloaded method computes the minimum of two characters.
*/
template<class T>
char TClass<T>::min(char a,char b)
{
return (a < b)?a:b ;
}
/*----------------------------------------------------------------------------*/
/**
* This overloaded method computes the maximum of two integers.
*/
template<class T>
int TClass<T>::max(int a,int b)
{
return (a > b)?a:b ;
}
/*----------------------------------------------------------------------------*/
/**
* This overloaded method computes the maximum of two floating point numbers.
*/
template<class T>
float TClass<T>::max(float a,float b)
{
return (a > b)?a:b ;
}
/*----------------------------------------------------------------------------*/
/**
* This overloaded method computes the maximum of two integers.
*/
template<class T>
char TClass<T>::max(char a,char b)
{
return (a > b)?a:b ;
}
/*----------------------------------------------------------------------------*/
/**
* This overloaded method tests the equality of two integers.
*/
template<class T>
bool TClass<T>::isEqual(int a,int b)
{
if (a==b)
return true;
else
return false;
}
/*----------------------------------------------------------------------------*/
/**
* This overloaded method tests the equality of two floating point numbers.
*/
template<class T>
bool TClass<T>::isEqual(float a,float b)
{
if (a==b)
return true;
else
return false;
}
/*----------------------------------------------------------------------------*/
/**
* This overloaded method tests the equality of two characters.
*/
template<class T>
bool TClass<T>::isEqual(char a,char b)
{
if (a==b)
return true;
else
return false;
}
/*----------------------------------------------------------------------------*/
obviously the first is the header file and the second is the cpp file. I thought I had implemented the template correctly, but I keep getting errors when making it. Any advice?