C++ Logo

std-proposals

Advanced search

Re: [std-proposals] Allow downcasting at compile time if Derived has no extra member objects

From: Frederick Virchanza Gotham <cauldwell.thomas_at_[hidden]>
Date: Thu, 23 Feb 2023 00:55:45 +0000
On Thu, Feb 23, 2023 at 12:52 AM Frederick Virchanza Gotham
<cauldwell.thomas_at_[hidden]> wrote:
>
> The rule could be as follows: You can use 'static_cast' to cast from a
> Base class to a Derived class unless:
> (a) The Derived class has additional member objects
> (b) The Base class has no virtual functions and is therefore not
> polymorphic, but the Derived class has at least one virtual function
> and is therefore polymorphic


Actually I missed one. There's one more:

(c) All of the extra member functions defined in the Derived class
must be non-virtual

Received on 2023-02-23 00:55:57