Warning: file_get_contents(/data/phpspider/zhask/data//catemap/6/cplusplus/148.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/4/unix/3.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C++ 递归类头包括_C++_Unix_Recursion_Header Files - Fatal编程技术网

C++ 递归类头包括

C++ 递归类头包括,c++,unix,recursion,header-files,C++,Unix,Recursion,Header Files,我需要包含递归类头文件 “Foo.h” “Bar.h” 在这种情况下,我会遇到如下错误 “类”未命名类型 考虑一下,在本例中,Foo是一个主类,它包含许多其他类作为成员。但是对于一个成员,我需要双向连接 那么我为什么会遇到这样的问题呢?使用前向声明: #ifndef FOO_H #define FOO_H class Bar; class Foo { public: Bar* barMember; }; #endif 以及: 您只需要在包含实现的.cpp文件中包含相应的头文件,这样

我需要包含递归类头文件

“Foo.h” “Bar.h” 在这种情况下,我会遇到如下错误

“类”未命名类型

考虑一下,在本例中,
Foo
是一个主类,它包含许多其他类作为成员。但是对于一个成员,我需要双向连接


那么我为什么会遇到这样的问题呢?

使用前向声明:

#ifndef FOO_H
#define FOO_H

class Bar;

class Foo
{
public:
    Bar* barMember;
};
#endif
以及:


您只需要在包含实现的.cpp文件中包含相应的头文件,这样就不会相互包含。

使用前向声明:

#ifndef FOO_H
#define FOO_H

class Bar;

class Foo
{
public:
    Bar* barMember;
};
#endif
以及:


您只需要在包含实现的.cpp文件中包含相应的头文件,这样就不会相互包含。

Huh,谢谢。。你真的节省了我的时间,我太累了。。。Thx againOh,不,再次,我不知道该怎么做,它给了我很多错误。如远期申报。。。。。。。。。。。。。。。。。我不知道该怎么办…嗯,谢谢。。你真的节省了我的时间,我太累了。。。Thx againOh,不,再次,我不知道该怎么做,它给了我很多错误。如远期申报。。。。。。。。。。。。。。。。。我不知道该怎么办。。。
#ifndef FOO_H
#define FOO_H

class Bar;

class Foo
{
public:
    Bar* barMember;
};
#endif
#ifndef BAR_H
#define BAR_H

class Foo;

class Bar
{
public:
    Foo* fooMember;
};
#endif