#include <stdio.h>classBclass;classaclass{ Public: Friend Bclass; voidfunc () {PB-FUNCB (); } intdata; Bclass*PB;};classbclass{ Public: Friend AClass; voidFUNCB () {p-func (); } AClass*p; intdata;};intMain () {return 0;}
Compilation Result:
1>------Started Build: Project: ABC, configuration: Debug Win32------
1> main.cpp
1>d:\cpptest\abc\abc\main.cpp: Error C2027: "Bclass" is used with undefined type
1> D:\cpptest\abc\abc\main.cpp (5): See Declaration of "Bclass"
1>d:\cpptest\abc\abc\main.cpp: Error C2227: The left side of "->FUNCB" must point to class/struct/union/generic type
Class A contains a pointer to Class B, and the method calls the Class B method, Class B contains a class of pointers, also called a method, did not take half a day
Find the Great God, said: Although you affirm the class B, but, the compiler just know there is this thing, and there is no way to implement, to put separate, header file one, CPP a
class Bclass; class aclass{ public void Func (); int data; Bclass * PB;}; class bclass{ public void Funca () {p ->func (); } aclass * P; int data;};
Put the implementation in the CPP
#include"Aclass.h"void Aclass::func () { PB-andFunca ();}
Perfect solution.
Inspire C + + to write things, or to separate the class into two inside, the first file, CPP a
C + + A class contains a class B pointer, Class B contains a class A pointer to the case