gpt4 book ai didi

c++ - 标准布局和继承

转载 作者:塔克拉玛干 更新时间:2023-11-03 06:57:52 24 4
gpt4 key购买 nike

二等舱不是标准布局是什么原因? (Visual Studio C++)

#include <iostream>
#include <type_traits>

struct A
{
int i;
};

struct B : public A
{
};

std::cout << "is_standard_layout<B> == "
<< std::boolalpha
<< std::is_standard_layout<B>::value // gives false
<< std::endl;

最佳答案

根据this MSVC 从版本 8 开始支持内置类型特征,但 this好像说你需要版本 11。

9.7将标准布局类定义为:

  • has no non-static data members of type non-standard-layout class (or array of such types) or reference,
  • has no virtual functions (10.3) and no virtual base classes (10.1),
  • has the same access control (Clause 11) for all non-static data members,
  • has no non-standard-layout base classes,
  • either has no non-static data members in the most derived class and at most one base class with non-static data members, or has no base classes with non-static data members, and
  • has no base classes of the same type as the first non-static data member.

some explanation here .

关于c++ - 标准布局和继承,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/7108902/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com