Partager via


Avertissement C26466

N’utilisez static_cast pas de pannes. Un cast d’un type polymorphe doit utiliser dynamic_cast.

Voir aussi

C++ Core Guidelines Type.2

Exemple

struct Base {
    virtual ~Base();
};

struct Derived : Base {};

void bad(Base* pb)
{
    Derived* test = static_cast<Derived*>(pb); // C26466
}

void good(Base* pb)
{
    if (Derived* pd = dynamic_cast<Derived*>(pb))
    {
        // ... do something with Derived*
    }
    else
    {
        // ... do something with Base*
    }
}