Reputation: 1
After a little bit searching I learned that I could call a parent method like this:
Base class :
class Base
{
public:
Base();
child *children; // instance of the child is needed on the base
float theDelegate(char *arg);
Then child class :
class child: public Base //**** problem
{
public:
...
But when I am trying to add the public Base
line, I get an error that he does not know Base
.
So then I include base
to the child
, with this :
#include "Base.hpp"
This time the child can see the parent ,but right when I include the base
on the child
I get an error on the parent because they include each other .
child *children; - unknown type name child - appear only if I include parent in the child
What am I doing wrong here ? How should it be done ?
Upvotes: 0
Views: 105
Reputation: 670
Use forward-declaration:
File Base.hpp:
class Child; // forward declaration
class Base {
public:
Child* child;
// whatever
};
File Child.hpp:
#include "Base.hpp"
class Child : public Base {
// whatever
};
Upvotes: 5