I have an assignment which is pretty basic in theory; I just have to receive some information for a person and then output it back out along with some other already inputted data. I believe I'm doing everything my professor taught me, but I'm getting a whole mess of errors. If I could get some help that would be great!
In file included from main.cpp:4:0:
cpersoninfo.h:38:1: error: invalid use of template-name 'CPersonInfo' without an argument list
cpersoninfo.h:46:1: error: invalid use of template-name 'CPersonInfo' without an argument list
cpersoninfo.h:54:1: error: invalid use of template-name 'CPersonInfo' without an argument list
cpersoninfo.h:62:14: error: expected class-name before '::' token
cpersoninfo.h:70:1: error: 'T' does not name a type
cpersoninfo.h:75:1: error: 'T' does not name a type
cpersoninfo.h:80:5: error: 'template<class T> class CPersonInfo' used without template parameters
cpersoninfo.h:80:27: error: non-member function 'int GetAge()' cannot have cv-qualifier
cpersoninfo.h: In function 'int GetAge()':
cpersoninfo.h:82:12: error: 'm_age' was not declared in this scope
cpersoninfo.h: At global scope:
cpersoninfo.h:85:8: error: 'template<class T> class CPersonInfo' used without template parameters
cpersoninfo.h:85:31: error: non-member function 'std::string GetName()' cannot have cv-qualifier
cpersoninfo.h: In function 'std::string GetName()':
cpersoninfo.h:87:12: error: 'm_fullName' was not declared in this scope
cpersoninfo.h: At global scope:
cpersoninfo.h:90:5: error: 'template<class T> class CPersonInfo' used without template parameters
cpersoninfo.h:90:34: error: non-member function 'int GetNameLength()' cannot have cv-qualifier
cpersoninfo.h: In function 'int GetNameLength()':
cpersoninfo.h:93:18: error: 'm_fullName' was not declared in this scope
cpersoninfo.h:93:28: error: 'strlen' was not declared in this scope
cpersoninfo.h: At global scope:
cpersoninfo.h:97:6: error: 'template<class T> class CPersonInfo' used without template parameters
cpersoninfo.h:97:29: error: variable or field 'SetWeight' declared void
cpersoninfo.h:97:29: error: 'T' was not declared in this scope
cpersoninfo.h:102:6: error: 'template<class T> class CPersonInfo' used without template parameters
cpersoninfo.h:102:29: error: variable or field 'SetHeight' declared void
cpersoninfo.h:102:29: error: 'T' was not declared in this scope
cpersoninfo.h:107:6: error: 'template<class T> class CPersonInfo' used without template parameters
cpersoninfo.h: In function 'void SetAge(int)':
cpersoninfo.h:109:5: error: 'm_age' was not declared in this scope
cpersoninfo.h: At global scope:
cpersoninfo.h:112:6: error: 'template<class T> class CPersonInfo' used without template parameters
cpersoninfo.h: In function 'void SetName(std::string)':
cpersoninfo.h:114:5: error: 'm_fullName' was not declared in this scope
cpersoninfo.h: In function 'std::string GetName()':
cpersoninfo.h:88:1: warning: control reaches end of non-void function [-Wreturn-type]
cpersoninfo.h: In function 'int GetAge()':
cpersoninfo.h:83:1: warning: control reaches end of non-void function [-Wreturn-type]
Nearly all of these errors are related to the use of the template. I've been cross-referencing my textbook and my notes from class, and as far as I can tell, I'm doing what I should be, but I'm obviously not doing something right.
If I could get some help that would be great, thanks!
#ifndef CPERSONINFO_H
#define CPERSONINFO_H
#include <iostream>
#include <string>
// using namespace std; // *** do not have this in a header filetemplate <class T>
class CPersonInfo
{
public:
// constructors
CPersonInfo();
CPersonInfo(const CPersonInfo &other);
CPersonInfo(T weight, T height, int age, std::string fName);
~CPersonInfo(); // Destructor
// member functions
T GetWeight() const;
T GetHeight() const;
int GetAge() const;
std::string GetName() const;
int GetNameLength() const;
void SetWeight(T weight);
void SetHeight(T height);
void SetAge(int age);
void SetName( std::string fName );
private:
T m_weight; // pounds
T m_height; // inches
int m_age; // years // ****** not a pointerstd::string m_fullName;
};
template < class T >
CPersonInfo<T>::CPersonInfo()
{
m_weight = 0;
m_height = 0;
m_age = 0;
m_fullName = "NONE";
}
// ...
template < class T >
CPersonInfo<T>::~CPersonInfo()
{
// **** empty
}
template < class T >
T CPersonInfo<T>::GetWeight() const
{
return m_weight;
}
// ...
template < class T >std::string CPersonInfo<T>::GetName() const
{
return m_fullName;
}
// and like-wise for all the other member functions
// ...
#endif // CPERSONINFO_H
That fixed most of the errors, thanks! I was able to fix the rest and got the code to compile, but now I get a segmentation fault when I try to run it.
EDIT: Nevermind! I realized I forgot to delete the pointers- they were put there by my professor for some reason. Getting rid of them fixed it. Thank you! :)