Only have one, unique "header guard" in each file. At the moment, your defining RANDOMCLASSHEADER_H_INCLUDED in every file, so for the other two the preprocessor will just skip over the rest of that file until the appropriate #endif is reached.
And no, as it stands you can't just delete them, because they're all referencing each other (ie, cust calls human calls cust). If you just deleted all the header guards, you'd end up with multiple declarations.
Each header file needs one and only one include guard. For each of them, you need a unique symbol (the word after #define ). Also notice that #ifndef (if not defined) and #endif are a pair. The first file you posted has one #ifndef and two #endif s. As I showed you in the other thread, the basic structure of a header file is this:
If the class inherits or uses a type declared in a different header file, you need to #include it. The #include directive simply copies and pastes text. An include guard prevents a header file from being copied twice into the same translation unit (which is the .cpp file plus all its #include s).
If, however, the class uses a pointer or reference to a type declared elsewhere, all you need is a forward declaration, so the file will look like this:
1 2 3 4 5 6 7 8 9 10
#ifndef FOO
#define FOO
class Bar; // forward declaration
class Foo {
// ...
};
#endif
1. you have a lot of unused variable - this is just a warning or information. You probably are going to use these variables.
2. the human::human() constructor function does not have a body ( that is to say you have not defined it).
Also - To continue what Pax has started - you should make the customer() and staff() constructors public as well and define (give them bodies) as well.
The linker is saying that during the customer constructor, - when it tried to link to the human base class constructor Human::Human() function it couldn't find it.
(all derived classes have to make a call to it's immediate base class constructor first - either implicitly or explicitly)
Your customer class inherits from the Human class, so the Constructor of the Customer Class (Customer::Customer()) calls the constructor of the Human class (Human::Human()), but can not find it. Do you have a human.cpp file?
Nah, I don't have a human.cpp file sorry. So I need to make a constructor in a .cpp for :
1 2 3 4
Human::Human()
{
}
to declare a function for
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19
#ifndef HUMAN_H_INCLUDED // must be unique!
#define HUMAN_H_INCLUDED
class Human
{
public:
Human();
Human(int identity);
void setID(int identity);
int getID();
private:
int human_identity;
};
#endif
Thanks alot mate I've got it working now, time to test if the inheritance part is work. What do you reckon the best way to do this would be? I was thinking like this: