—UPDATED —
I have problems when including headers and cpp files in my project, so here are the files:
Person.h
#ifndef PERSON_H
#define PERSON_H
class Person {
private:
string firstName;
string lastName;
long NID;
public:
Person();
void toString();
string get_firstName() {
return firstName;
}
string get_lastName() {
return lastName;
}
long get_NID() {
return NID;
}
};
#endif
Teacher which extends Person
Teacher.h
#include "Person.h"
#include <iostream>
#ifndef TEACHER_H
#define TEACHER_H
class Teacher : public Person {
private:
int avg_horarium;
public:
Teacher();
void toString();
int get_avg_horarium() {
return avg_horarium;
}
};
#endif
Then here is Teacher.cpp:
#include "Teacher.h"
using namespace std;
Teacher::Teacher() : Person() {
cout << "Enter average monthly horarium: ";
cin >> avg_horarium;
}
void Teacher::toString() {
Person::toString();
cout << "Average monthly horarium: " << avg_horarium;
}
The other class which extends Person is Student and since it’s similar to teacher i won’t poste it here. My question is what am i doing wrong to get all these errors on the screenshot:
http://s14.postimage.org/45k08ckb3/errors.jpg
The problem is your incorrect treatment of
stdafx.hfile. In MSVC compilers, when precompiled headers are enabled, everything before#include "stdafx.h"line is ignored.Firstly, stop including
stdafx.hinto header (.h) files.stdafx.his supposed to be included into implementation (.cpp) files. In your case,#include "stdafx.h"should be placed intoPerson.cppandTeacher.cpp, not intoPerson.handTeacher.h.Secondly, either disable precompiled headers in your project, or make sure that
#include "stdafx.h"is always the very first meaningful line in each of your implementation files. All other#includedirectives should go after#include "stdafx.h", not before.