There is no forwarding of the inheritance declaration, even if you only deal with pointers. When it comes to conversions between pointers, sometimes the compiler needs to know the details of the class in order to make the conversion right. This applies to multiple inheritance. (In a particular case, we can distinguish some parts of the parts of the hierarchy that use only one inheritance, but this is not part of the language.)
Consider the following trivial case:
The result obtained (using 32-bit visual studio 2010):
A: 0018F748, B: 0018F74C, C: 0018F748
So, for multiple inheritance when converting adjacent pointers, the compiler must insert some pointer arithmetic to get the correct conversions.
That is why, even if you are dealing only with pointers, you cannot redirect the declaration of inheritance.
As to why this would be useful, it would improve compilation times when you want to use the return types of co-options instead of using throws. For example, this will not compile:
class RA; class A { public: virtual RA *fooRet(); }; class RB; class B : public A { public: virtual RB *fooRet(); };
But it will be:
class RA; class A { public: virtual RA *fooRet(); }; class RA { int x; }; class RB : public RA{ int y; }; class B : public A { public: virtual RB *fooRet(); };
This is useful if you have objects of type B (not pointers or references). In this case, the compiler is smart enough to use a direct function call, and you can use the returned type RB * directly without casting. In this case, as a rule, I go ahead and do the return type RA * and perform a static action on the return value.
user1332054 Apr 13 2018-12-12T00: 00Z
source share