If I have a simple two-class relationship like this, I will get this error: ‘Parent’ does not name a type
. I do understand why this error occurs, but how can I prevent this?
parent.h
#ifndef PARENT_H
#define PARENT_H
#include "child.h"
class Parent {
Child b;
};
#endif
child.h
#ifndef CHILD_H
#define CHILD_H
#include "parent.h"
class Child {
Parent a;
};
#endif
impl.cpp
#include "parent.h"
Parent b;
int main() {
}