C++ - Creating a god object
Posted
by
Greg Kritzman
on Stack Overflow
See other posts from Stack Overflow
or by Greg Kritzman
Published on 2014-06-03T02:50:17Z
Indexed on
2014/06/03
3:26 UTC
Read the original article
Hit count: 133
c++
Hypothetical situation that I'm struggling to get my head past.
HoldsFooBar.h:
#include "foo.h"
#include "bar.h"
class HoldsFooBar{
foo F;
bar B;
};
foo.h:
//includes?
class foo{
HoldsFooBar *H;
void Baz();
};
bar.h:
//includes?
class bar{
HoldsFooBar *H;
void Qux();
};
I'm trying to get F to get a hold of B. In all other languages I've worked with, I would be able to H->B.Qux();
, but I'm totally lost in C++. At the includes lines in foo.h
and bar.h
, it seems like my options are to forward-declare class HoldsFooBar;
but then I can only access H, and F and B cannot see each other. Likewise, I can #include "HoldsFooBar.h"
but because of my include guards, something ends up not getting linked properly, so the program doesn't run.
Is what I'm trying to do even possible? Thank you very much! Any help would be appreciated!
© Stack Overflow or respective owner