Hi guys,
I'm very new to C++, although have some experience in Java.
Anyway, I'm currently learning about separating code through header files (for class declarations) and storing the definitions in .cpp files which is simple enough.
However, the code I have been given does not compile and I can't figure out why.
I use two files, Person.h and Person.cpp (neither is the driver for my "program", but before I even create the driver .cpp file, I can't get Person.cpp to compile)
Person.h:
Code:
#ifndef PERSON_H
#define PERSON_H
class Person{
private:
string name;
char sex;
int age;
public:
Person(string name, char sex, int age);
Person();
string getName();
char getSex();
int getAge();
void setAge(int age);
};
#endif
And now the corresponding Person.cpp:
Code:
#include "Person.h"
#include <string>
Person::Person(string name, char sex, int age)
{
this->name = name;
this->sex = sex;
setAge(age);
}
Person::Person(){ name = "Default Name"; setAge(0); }
string Person::getName(){ return name; }
char Person::getSex() { return sex; }
int Person::getAge() { return age; }
void Person::setAge() { this->age = age; }
This is pretty simple stuff and our tutor gave it to us, however in this current form it does not compile, and I can't figure out why.. Any ideas?
Cheers.