I'm pretty new to C++ and working with books and youtube and here in the same time, but i got a weird problem that I can't find a solution. I'm trying to inherit from a base class "Mother" to a derived class Daughter and it is not working for me, it says it need to
This code was taking from TheNewBoston, so thank u Bucky, just giving credits
C:\CppProjects\inheritance\Daughter.h|6|error: expected class-name before '{' token
I'm adding the main and the classes:
main:
#include <iostream>
#include "Mother.h"
#include "Daughter.h"
using namespace std;
int main()
{
Daughter t;
t.sayName();
}
Mother class:
#include "Mother.h"
#include <iostream>
#include "Daughter.h"
using namespace std;
Mother::Mother()
{
}
void Mother::sayName(){
cout<<"I am !!!"<<endl;
}
Mother header:
#ifndef MOTHER_H
#define MOTHER_H
class Mother
{
public:
Mother();
void sayName();
};
#endif // MOTHER_H
Daughter class:
#include "Daughter.h"
#include <iostream>
#include "Mother.h"
using namespace std;
Daughter::Daughter()
{
}
Daughter header:
#ifndef DAUGHTER_H
#define DAUGHTER_H
class Daughter : public Mother
{
public:
Daughter();
};
#endif // DAUGHTER_H
I looked in most of the searches in here and nothing found, I even tried noob style and added std::, it has nothing to do with it.
thank you all of you who are willing to try!
just so you know, when I'm trying to put all of the code in one file, it works great:
the new main:
#include <iostream>
using namespace std;
class Mother
{
public:
Mother();
void sayName(){
cout<<"I am!!!!"<<endl;
}
};
class Daughter: public Mother
{
public:
Daughter();
};
int main()
{
Daughter t;
t.sayName();
}