0

I learned C++ using the Code::Blocks. However, the compiler gives me an error in the file Daughter.h, line 6, saying "error: expected-class name before '{' token" when I am trying to implement the inheritance. That confuses me more because the tutorial I'm watching using Code::Blocks and compiler in this tutorial does not gives any errors, it in fact works perfectly. I am a bit frustrated at this point. Does anybody know how to make it work? Here are all of my files:

main.cpp

//main.cpp
#include "Daughter.h"
#include "Mother.h"
#include <iostream>
using namespace std;

int main()
{
    Mother jelo;
    jelo.sayname();
    Daughter tina;
    tina.sayname();
}

Mother.h

//Mother.h
#ifndef MOTHER_H
#define MOTHER_H


class Mother
{
    public:
        Mother();
        void sayname();
};

#endif // MOTHER_H

Mother.cpp

//Mother.cpp
#include "Daughter.h"
#include "Mother.h"
#include <iostream>
using namespace std;

Mother::Mother()
{
}

void Mother::sayname() {

    cout << "I am Roberts" << endl;

}

Daughter.h

//Daughter.h
#ifndef DAUGHTER_H
#define DAUGHTER_H


class Daughter: public Mother
{
    public:
        Daughter();
};

#endif // DAUGHTER_H

Daughter.cpp

//Daughter.cpp
#include "Daughter.h"
#include "Mother.h"
#include <iostream>
using namespace std;

Daughter::Daughter()
{
}
MarcoPolo
  • 3
  • 2

1 Answers1

0

Daughter.h should #include "Mother.h", because it needs to know what Mother is.

If the tutorial doesn't say that, the tutorial is wrong.

Learn C++ from a good book, instead.

Lightness Races in Orbit
  • 378,754
  • 76
  • 643
  • 1,055