On 14 June 2014 18:04, David Krauss <
pot...@gmail.com> wrote:
> On 2014–06–14, at 8:36 PM, Ville Voutilainen <
ville.vo...@gmail.com>
> wrote:
> The harm is that a derived class that inherits a base B privately
> is-not-a-B,
> the only classes that can convert derived to B is derived itself and
> its friends,
> That simply states the rule in question.
The "rule in question" doesn't talk about a higher-level design concept which
"is-a" represents.
>
> and sure as hell downcasting B to derived makes little sense if derived
> inherits
> B privately.
>
>
> If B inherently knows itself to be a base of D, then it’s not really very
B doesn't "inherently know" that it happens to be a base of its template
argument.
> private. In CRTP the inheritance information is passed explicitly through
> the template parameter, so there’s no secret to keep.
Except the secrets D keeps by design - it's not a B, and it's not convertible
from B nor to B. Base classes do not get special treatment and can't subvert
the access control of derived classes any more than any other classes can.
> I’m not suggesting to open all of D to B, but only to expose the base class
> subobject *to itself*.
I don't know that that's supposed to mean.
>
> I can easily find a way to do CRTP with non-public bases: add a virtual
> function
> to B that returns T*, and have derived classes override it. Example:
> No way. Avoiding virtual dispatch is a main advantage of CRTP.
You don't have to perform that virtual dispatch on every call. Alternatively,
you can pass the pointer to the derived object up to the base.
> If it can be done with such a “dynamic downcast,” why not support a more
> efficient semantic equivalent?
Because it breaks design exceptions without sufficient motivation to do so?