#include"B_wnd.h"
class A_wnd{
int xy;
B_wnd b_obj;
};
#include"A_wnd.h"
class B_wnd{
int bx;
A_wnd a_obj;
};
First of all why do you need a circular reference? Any real need or you want just to test?
First of all the headers will have circular reference. You can use a include guard to over come that. Mostly all advanced C/C++ processors can avoid it, but always when you include headers use include guards. In Microsoft VCC then I think you can use
#pragma once
After you overcome this you have a second problem.
Suppose you create an object of type
A_wnd
.
When the constructor of
A_wnd
is called it calls the constructors of
B_wnd
. Inside this again constructor of
A_wnd
will be called. This is a recursive problem. You will go out of stack and there will be crash.
You can use pointers or reference instead of real objects.