2つのクラスがあるとしましょう:
// a.h
#ifndef A_H
#define A_H
#include "b.h"
class A {
public: void a() {
B* b = new B(this);
}
}
#endif
// b.h
#ifndef B_H
#define B_H
#include "a.h"
class B {
public: B(A* a) {
// ...
}
}
#endif
A has not been declared
クラス A はクラス B を参照し、クラス B はクラス A をまだ ah で宣言していないため、このコードはエラーを発生させます。
では、A のインスタンスを B に渡すにはどうすればよいでしょうか。