Warning: file_get_contents(/data/phpspider/zhask/data//catemap/6/cplusplus/136.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++_Compiler Errors_Circular Dependency_Forward Declaration - Fatal编程技术网

C++ ';使用未定义的类型';使用循环包含时出错

C++ ';使用未定义的类型';使用循环包含时出错,c++,compiler-errors,circular-dependency,forward-declaration,C++,Compiler Errors,Circular Dependency,Forward Declaration,我编写了两个具有这些依赖项的类 //a.h class B: class A{ B *b ; A() { b = new B(this);} print(); } // b.h class A; class B{ A* a; B(A *_a){ this->a = _a } void foo() { a->print(); } // here i have error : use of undefined type a

我编写了两个具有这些依赖项的类

//a.h
class B: 
class A{
 B *b ;
 A() { b = new B(this);}
 print();
}



  // b.h
    class A;
    class B{
     A* a;
     B(A *_a){ this->a = _a }
     void foo() { a->print(); } // here i have error : use of undefined type a
   }
如果我注释“a->print()”,代码将编译,其他函数也会工作,但是当我在类B中使用类a的指针时,我会得到以下错误:

“使用未定义的类型a”

有人能解决我的问题吗


谢谢

您需要将方法的实现移到头文件外部和实现文件内部

执行
a->print()
新B(此)
,需要完整的定义