a.h:
#include  "b.h"
class a
{
public :
a();
b *b1;
public:
b *get_b();
};
b.h:
#include  "a.h"
class b
{
public:
b();
  a *get_a();
private:
a *a1;
}还是报错
vc\sample1\dd\a.h(1) : warning C4182: #include nesting level is 363 deep; possible infinitefatal error C1076: compiler limit : internal heap limit reached; use /Zm to specify a higher limit

解决方案 »

  1.   

    请在每个头文件前面加上:
    #if !defined A_H;//头文件
    #define A_H;     //头文件 
      

  2.   

    #ifndef A_H
    #define A_H
    /******/
    #endif#ifndef B_H
    #define B_H
    /*******/
    #endif
      

  3.   

    不要在H文件中互相include!!!!!!a.h:class b;
    class a
    {
    public :
    a();
    b *b1;
    public:
    b *get_b();
    };b.h:
    class a;
    class b
    {
    public:
    b();
      a *get_a();
    private:
    a *a1;
    }c.cpp#include "a.h"
    #include "b.h"
    ....就可以了。
      

  4.   

    to verybigbug() 
    只怕不行吧,这样就有个#include 先后问题,麻烦
    不如用
    #ifndef
    #define
    ...
    #endif
    方式
    虽然项目大时修改一项文件编译慢些,但是使用更自由
      

  5.   

    //mainfrm.h
    class CMyBar;
    ...
    CMyBar m_wndMyBar;
    //mainfrm.cpp
    #include "mybar.h"
    #include "mainfrm.h"//compile
    mainfrm.h(48) : error C2079: 'm_wndMyBar' uses undefined class 'CMyBar'//为何不行,能解释解释吗?
      

  6.   

    在你的每一个头文件中,都加入
    #if !defined(_HeaderFileName_H)
    ...
    ... // 这里是你的头文件的代码
    ...
    #endif加入了这个以后,你可以随便的包含,都不会出现任何的问题。
      

  7.   

    在a.h中:
    #ifndef A_H
    #define A_H#endif在b.h中:
    #ifndef B_H
    #define B_H#endif 
      

  8.   

    回复人: robothn(雷鸟) (  ) 信誉:100  2002-04-16 09:27:00  得分:0  
     
     
      //mainfrm.h
    class CMyBar;
    ...
    CMyBar m_wndMyBar;
    //mainfrm.cpp
    #include "mybar.h"
    #include "mainfrm.h"//compile
    mainfrm.h(48) : error C2079: 'm_wndMyBar' uses undefined class 'CMyBar'//为何不行,能解释解释吗?-----------------------------------------------------
    必须在所有用过mainfrm.h的cpp文件中都加入#include "mybar.h"
    如果别的cpp中也#include "mainfrm.h"而没有#include "mybar.h"
    当然不行!
      

  9.   

    //mainfrm.h
    class CMyBar;
    ...
    CMyBar m_wndMyBar;
    //mainfrm.cpp
    #include "mybar.h"
    #include "mainfrm.h"//compile
    mainfrm.h(48) : error C2079: 'm_wndMyBar' uses undefined class 'CMyBar'//为何不行,能解释解释吗?
    ----------------------------------
    请把:
    class CMyBar;去掉;
    然后将:#include "mybar.h"放到mainfrm.h去!
      

  10.   

    #include  "common.h"
    #ifndef __A__H_
    #define __A__H_
    class a
    {
    public :
        a();
        b *b1;
    public:
        b *get_b();
    };b.h:
    #include  "common.h"
    #ifndef __B__H__
    #define __B__H__
    class b
    {
    public:
        b();
      a *get_a();
    private:
        a *a1;
    };  //<------------你掉了一个分号#endif
    common.h
    #include "a.h"
    #include "b.h"
    class a;
    class b;
      

  11.   

    #include  "common.h"
    #ifndef __A__H_
    #define __A__H_
    class a
    {
    public :
        a();
        b *b1;
    public:
        b *get_b();
    };
    #endifb.h:
    #include  "common.h"
    #ifndef __B__H__
    #define __B__H__
    class b
    {
    public:
        b();
      a *get_a();
    private:
        a *a1;
    };  //<------------你掉了一个分号#endif
    common.h#ifndef __COMMON__H
    #define __COMMON__H
    #include "a.h"
    #include "b.h"class a;
    class b;
    #endif
      

  12.   

    谢谢各位
    加了
    #ifndef A_H
    #define A_H
    /******/
    #endif 解决了循环include的问题。  给分
    但是不知道为什么 #include "a.h" 后还要声明class a;
     a.h 中不是已经包含了 a 的声明吗?