Re: Partial classes
Adrian Hawryluk wrote:
Sorry, is this better?
BTW still based on the example, only A is dependent
on B fully. B does not need a full include in the
header (in the .cpp yes but not the header). A forward
declaration of class A in B is sufficient in the header.
But I am sure you know this :)
<header file="A.h">
#if !defined A_H
# define A_H
// Stub for forward referencing
class A;
# include ?B.h?
class A
{
// Interface functions
void f(B* b, B::b_e enums);
...
};
#endif
</header>
<header file="B.h">
#if !defined B_H
# define B_H
// Stub for forward referencing
class B;
# include ?A.h?
class B
{
public:
enum b_e { enum1, enum2 };
void f(A* a); ///< here is the dependent
// Interface functions
...
};
#endif
</header>
As for the actual example, it would be too long and have lots of extra
non-relevant stuff, but trust me it does occur and has occurred at other
times before that.
I do understand that it does occur and based on your suggestions, I
would do:
1) Hopefully your compiler is smart to do empty base class optimization
to eliminate your overhead.
1. Base classes would have a explicit size of 1, adding a small amount
of overhead.
Check this for reference about the optimization:
http://www.cantrip.org/emptyopt.html
2) doing the base class thing also kind of implies to me that you may
opt to namespace your enumerated independent of both class A and class
B and you can even reintroduce the enumerated type back into class B
if that is even necessary.
HTH