Problem with inheritance
Hello,
I am new to c++ and I can't seem to get this code to work after following everything exactly as it was in the tutorial:
1 2 3 4 5 6 7 8 9 10 11 12 13
|
#include <iostream>
#include "Daughter.h"
#include "Mother.h"
using namespace std;
int main()
{
Mother mo;
mo.sayName();
Daughter tina;
tina.sayName();
}
|
1 2 3 4 5 6 7 8 9 10 11 12
|
#ifndef MOTHER_H
#define MOTHER_H
class Mother
{
public:
Mother();
void sayName();
};
#endif // MOTHER_H
|
1 2 3 4 5 6 7 8 9 10 11 12 13
|
#include <iostream>
#include "Daughter.h"
#include "Mother.h"
using namespace std;
Mother::Mother()
{
//ctor
}
void Mother::sayName(){
cout << "I am a Roberts" << endl;
}
|
1 2 3 4 5 6 7 8 9 10 11
|
#ifndef DAUGHTER_H
#define DAUGHTER_H
class Daughter: public Mother
{
public:
Daughter();
};
#endif // DAUGHTER_H
|
1 2 3 4 5 6 7 8 9
|
#include <iostream>
#include "Daughter.h"
#include "Mother.h"
using namespace std;
Daughter::Daughter()
{
//ctor
}
|
The error I get is on line 6 of Daughter.h
Daughter.h:6: error: expected class-name before '{' token
daugher.h should be #including mother.h
Or else you have to be sure mother.h is included before daughter.h, but it's better if you just put the include in the header.
ok, thank you, I tried it both ways and they both built successfully :)
Topic archived. No new replies allowed.