Re: [Dev-C++] indirect references problem
Open Source C & C++ IDE for Windows
Brought to you by:
claplace
|
From: Per W. <pw...@ia...> - 2007-09-26 16:32:37
|
Normally, you can break circular references by just adding the text:
class Police;
in the top of PoliceMan.h file and/or addding
class PoliceMan;
in the top of Police.h.
This adds the class to the known name space. However, this only works as
long as the compiler doesn't need to know the full size of the class.
So class Police can reference pointers or references to Police but can not
declare instances of PoliceMan, and can not access members or methods in
PoliceMan. The second part isn't a problem, since the file Police.cpp
(that have included both Police.h and PoliceMan.h) can access members and
methods of the PoliceMan class.
/pwm
On Wed, 26 Sep 2007, Laura Lozano wrote:
> Hello,
>
> I would like to do a double reference, I mean, I have two classes Police and
> PoliceMan in two files: Police.h and PoliceMan.h , the class Police have a
> vector of pointers of PoliceMan: vector<PoliceMan*>, so Police.h include
> PoliceMan.h, and I would like include Police.h into PoliceMan.h but I have
> errors; This is that I would like to do:
>
> //Police.h
> #include "PoliceMan.h"
> class Police{
> private:
> vector<PoliceMan*> policeMen;
>
> ......
>
> //PoliceMan.h
> #include "Police.h"
> class PoliceMan{
> private:
> Police* myPolice;
> ....
>
> Is there any way to do that? Thank you
>
|