警告 C26466
請勿使用
static_cast
倒播。 來自多型別的轉換應該使用 dynamic_cast。
另請參閱
範例
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*
}
}