C++ Logo

std-proposals

Advanced search

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

From: Thiago Macieira <thiago_at_[hidden]>
Date: Thu, 11 Jul 2024 06:40:57 -0700
On Thursday 11 July 2024 00:34:32 GMT-7 Frederick Virchanza Gotham via Std-
Proposals wrote:
> This program successfully compiles, and as expected, segfaults.

You forgot the typeid check that your original code had.

I wasn't precise in my reply. You had written:

    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);

I had meant you can use static_cast in the case of the pointer arithmetic you
had there, not the whole thing.

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

Received on 2024-07-11 13:41:01