#include<iostream> using namespace std; class A; class B { public : B(A * a){ a->c = 5; } }; class A { public: int c; void set() { B b(this); cout<<c; } }; void main() { A a; a.set(); } /* error C2027: use of undefined type 'A' see declaration of 'A' error C2227: left of '->c' must point to class/struct/union*/
在定义类B之前,只是声明了类A,这个声明是前向声明,在类A声明之后,定义之前,类A 是不完整类型,即已知A是一个类型,但不知道包含哪些成员。 对于不完整类型,只能定义一个A类型的指针或引用,且不能访问它的成员,因为编译器只知道有类A存在而不知道类A到底是什么。
error C2027: use of undefined type 'A' see declaration of 'A'
最新推荐文章于 2021-06-19 11:21:37 发布