☰
  • 首页
  • 规则分类
  • 项目介绍
search
•••

对象解引用成员指针时,对象的动态类型不包含成员指针引用的成员

C++-Undefined-Behavior-42
目录 › next › previous

示例:

struct A { int a; };
struct B { int a, b; };

int foo(A* pa) {
    B* pb = (B*)pa;
    int B::* m = &B::b;
    return pb->*m;         // Undefined behavior
}

依据

ISO/IEC 14882:2003 5.5(4)-undefined ISO/IEC 14882:2011 5.5(4)-undefined
Copyright©2024 360 Security Technology Inc., Licensed under the Apache-2.0 license.