Is Reference type in C++ a POD type?

后端 未结 3 515
星月不相逢
星月不相逢 2021-02-08 21:33

Is Reference type in C++ a POD type too? Is int& is a POD type? and what about

struct Q { int& i; }

Anyone can help me?

3条回答
  •  自闭症患者
    2021-02-08 22:21

    A POD type is any intrinsic type or aggregate of intrinsic types (basically, anything that does not have a custom constructor, destructor, copy-constructor, copy-assignment operator, nor non-static pointer-to-member types (more details here)

    Since a member that references something must be set via a custom constructor, it would violate the first requirement. In short, a struct that declares a reference type as a member is not a POD type.

提交回复
热议问题