Very basic inheritance: error: expected class-name before ‘{’ token

I’m trying to learn c++ and I’ve stumbled upon a error while trying to figuring out inheritance.

Compiling: daughter.cpp In file included from /home/jonas/kodning/testing/daughter.cpp:1: /home/jonas/kodning/testing/daughter.h:6: error: expected class-name before ‘{’ token Process terminated with status 1 (0 minutes, 0 seconds) 1 errors, 0 warnings

My files: main.cpp:

#include "mother.h"
#include "daughter.h"
#include <iostream>
using namespace std;

int main()
{
    cout << "Hello world!" << endl;
    mother mom;
    mom.saywhat();
    return 0;
}

mother.cpp:

#include "mother.h"
#include "daughter.h"

#include <iostream>

using namespace std;


mother::mother()
{
    //ctor
}


void mother::saywhat() {

    cout << "WHAAAAAAT" << endl;


}

mother.h:

#ifndef MOTHER_H
#define MOTHER_H


class mother
{
    public:
        mother();
        void saywhat();
    protected:
    private:
};

#endif // MOTHER_H

daughter.h:

#ifndef DAUGHTER_H
#define DAUGHTER_H


class daughter: public mother
{
    public:
        daughter();
    protected:
    private:
};

#endif // DAUGHTER_H

and daughter.cpp:

#include "daughter.h"
#include "mother.h"

#include <iostream>

using namespace std;


daughter::daughter()
{
    //ctor
}

What I want to do is to let daughter inherit everything public from the mother class (=saywhat()). What am I doing wrong?

Leave a Comment