如何正确引用两个对象(双重链接的子对象和父对象)中的子对象和父对象?这样做时,我得到一个编译错误:**** does not name a type
. 我怀疑这与由于#define 标签而被省略的#include 语句有关。因此应该如何包含这些标签?
三个文件(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;
}