両方のオブジェクト (二重にリンクされた子と親) 内で子オブジェクトと親オブジェクトを適切に参照するにはどうすればよいですか? これを行うと、コンパイル エラーが発生します: **** does not name a type
. #define タグが原因で #include ステートメントが省略されていることに関係していると思われます。したがって、これらのタグをどのように含める必要がありますか?
次のように記述された 3 つのファイル (Parent.h、Child.h、main.cpp):
/* Parent.h */
#pragma once
#ifndef _CHILD_CLS
#define _CHILD_CLS
#include "Child.h"
class Parent {
public:
Parent() {}
~Parent() {}
void do_parent(Child* arg);
};
#endif
/* Child.h */
#pragma once
#ifndef _CHILD_CLS
#define _CHILD_CLS
#include "Parent.h"
class Child {
public:
Child() {}
~Child() {}
void do_child(Parent* arg);
};
#endif
/* main.cpp */
#include "child.h"
#include "parent.h"
int main()
{
Child a();
Parent b();
a.do_parent(Child& arg);
return 0;
}