Hey folks,
I am working on a project (its a continuation of my previous project)... but with a few additions. First off, i have to use class templates... I have used them before, but not when working with multiple class definitions and multiple files.
Below i will post sections of my Person.h, and Person.cpp files. I am getting linker errors with all of my functions when trying to edit them to work with templates. I am sure i am missing something rather obvious...
Person.h
#define PERSON_H
#include "340.h"
template <class T>
class Person;
template <class T>
class Person {
public:
Person();
virtual ~Person();
void setFirstName(T &x);
T getFirstName() const;
void setLastName(T &x);
T getLastName() const;
void setSSN(T &x);
T getSSN() const;
void setDOB(T &x);
T getDOB() const;
void setGender(T &x);
T getGender() const;
private:
string firstName;
string lastName;
string SSN;
string DOB;
string gender;
};
#endif //PERSON_H
Person.cpp
#include "Person.h"
/****************************************************************
FUNCTION: Person()
ARGUMENTS: none
RETURNS: none
NOTES: this is the Person() constructor
****************************************************************/
template <class T>
Person<T>::Person()
{
}
/****************************************************************
FUNCTION: ~Person()
ARGUMENTS: none
RETURNS: none
NOTES: this is the Person destructor
****************************************************************/
template <class T>
Person<T>::~Person()
{
}
/****************************************************************
FUNCTION: setFirstName(const string &x)
ARGUMENTS: const string &x - the first name of student
RETURNS: none
NOTES: this function sets the students first name
****************************************************************/
template <class T>
void Person<T>::setFirstName(T &x)
{
firstName = x;
}
/****************************************************************
FUNCTION: getFirstname() const
ARGUMENTS: none
RETURNS: string firstName
NOTES: this function returns the students first name
****************************************************************/
template <class T>
T Person<T>::getFirstName() const
{
return firstName;
}
...//more functions, but lots of space used... you could comment out the functions methods in the class definition if you wanted to try compiling?!
I hope someone sees an obvious mistake i am overlooking. My textbooks and previous projects all seem to be similar to what i have done on this...yet they seemed to work!
Thanks again folks