C++ Logo

std-proposals

Advanced search

Re: [std-proposals] Caching the offset for dynamic_cast

From: Thiago Macieira <thiago_at_[hidden]>
Date: Wed, 10 Jul 2024 15:33:31 -0700
On Wednesday 10 July 2024 15:13:57 GMT-7 Frederick Virchanza Gotham via Std-
Proposals wrote:
> if ( typeid(*p) == typeid(MostDerived) ) pd = p + offset;
> else if ( typeid(*p) == typeid(MostDerived2) ) pd = p + offset2;
> else if ( typeid(*p) == typeid(MostDerived3) ) pd = p + offset3;
> else pd = dynamic_cast<Derived*>(p);

You can just use static_cast there.

-- 
Thiago Macieira - thiago (AT) macieira.info - thiago (AT) kde.org
  Principal Engineer - Intel DCAI Platform & System Engineering

Received on 2024-07-10 22:33:36