class A
{
public:
   A();
   ~A();
   B* C();
};
class B
{
public:
   B();
   ~B();
};
为什么在编译A.CPP的时候会有问题呢?
  

解决方案 »

  1.   

    #include "B.H"
    class A 

    public: 
       A(); 
       ~A(); 
       B* C(); 
    }; 
      

  2.   

    点击"结贴去...",然后就在Edit上添写分数,然后再结贴就OK了
      

  3.   

    问题变了。。诺类定义改成这样呢。。
    class A
    {
    public:
       A();
      ~A();public:
       B* getB();
    }
    class B
    {
    public:
        B();
        ~B();
    public:
        A* m_pA;
        A* SetBA();
    }
    类A的头文件中加入B.h,类B 的头文件中加入A.h,这样好象通不过编译耶。。
      

  4.   

    在头文件中不要用#include "A.h",用class A;进行预定义,在cpp文件中#include "A.h"
      

  5.   

    用宏防止重复包含:在A.h中:
    #ifndef MYHFILE_A_H
    #define MYHFILE_A_H#include <B.h>
    .
    .
    .
    .
    .
    .
    #endif

    在B.h中:
    #ifndef MYHFILE_B_H
    #define MYHFILE_B_H#include <A.h>
    .
    .
    .
    .
    .
    .
    #endif

      

  6.   

    尽量不要在一个类的头文件中包含另一个类的头文件。这样写:
    // A.h
    class B;
    class A 

    public: 
       A(); 
      ~A(); 
       B* getB(); 
    };
    // B.h
    class A;
    class B 

    public: 
        B(); 
        ~B(); 
        A* m_pA; 
        A* SetBA(); 
    };
      

  7.   

    再补充一下,如果cpp文件中使用了某个类,是要在该cpp中包含对应的头文件的。