C
ctor
Hi,
I'm experiencing an annoying issue. Here is a simplified idea of what
I am trying to do. Inclusion guards aren't shown for readability. I
hope this isn't too confusing; I don't think a description would be as
clear as an example.
-----[ParentA.h]------
class ParentA {};
-----[ChildA.h]------
#include "ParentA.h"
#include "ChildB.h"
class ChildA: public ParentA { ChildB foo; };
-----[ParentB.h]------
class ParentA;
class ParentB {
virtual ParentA& getA() = 0;
};
-----[ChildB.h]------
#include "ParentB.h"
class ChildA;
class ChildB: public ParentB {
ChildA& getA();
};
---
When I try to compile my project, MSVC 2002 gives me the following
error message:
error C2555: 'ChildB::getA': overriding virtual function return type
differs and is not covariant from 'ParentB::getA'
I took this to mean that the problem is that the compiler doesn't
realize that ChildA is a type of ParentA because I forward-declared
ChildA instead of including its header file, so ChildB::getA looks
like an invalid signature. The problem is that if I replace the
forward-declaration with "#include ChildA.h", I encounter a dependency
issue, since ChildA.h also has to include ChildB.h because the ChildA
class contains a ChildB object.
Is there a way to specify that ChildA is a child of ParentA in a
forward-declaration? If not, does anyone have any suggestions for
getting around this problem?
Thanks.
I'm experiencing an annoying issue. Here is a simplified idea of what
I am trying to do. Inclusion guards aren't shown for readability. I
hope this isn't too confusing; I don't think a description would be as
clear as an example.
-----[ParentA.h]------
class ParentA {};
-----[ChildA.h]------
#include "ParentA.h"
#include "ChildB.h"
class ChildA: public ParentA { ChildB foo; };
-----[ParentB.h]------
class ParentA;
class ParentB {
virtual ParentA& getA() = 0;
};
-----[ChildB.h]------
#include "ParentB.h"
class ChildA;
class ChildB: public ParentB {
ChildA& getA();
};
---
When I try to compile my project, MSVC 2002 gives me the following
error message:
error C2555: 'ChildB::getA': overriding virtual function return type
differs and is not covariant from 'ParentB::getA'
I took this to mean that the problem is that the compiler doesn't
realize that ChildA is a type of ParentA because I forward-declared
ChildA instead of including its header file, so ChildB::getA looks
like an invalid signature. The problem is that if I replace the
forward-declaration with "#include ChildA.h", I encounter a dependency
issue, since ChildA.h also has to include ChildB.h because the ChildA
class contains a ChildB object.
Is there a way to specify that ChildA is a child of ParentA in a
forward-declaration? If not, does anyone have any suggestions for
getting around this problem?
Thanks.