哪项操作在这里不是琐碎的
Which operation is not trivial here?
编译器同意,下面的X
和Y
是默认的可构造的,但不是微不足道的(演示(。
#include <type_traits>
struct X { int x {}; };
struct Y { int y = 0; };
static_assert(std::is_default_constructible_v<X>);
static_assert(std::is_default_constructible_v<Y>);
static_assert(!std::is_trivially_default_constructible_v<X>);
static_assert(!std::is_trivially_default_constructible_v<Y>);
为什么它们不是琐碎的?根据cppreference.com(请参阅is_trivially_constructible
(,在默认构造期间必须调用一个非平凡的操作。那是哪一个?
https://en.cppreference.com/w/cpp/language/default_constructor#Trivial_default_constructor说:
如果以下所有情况都为真,则类T的默认构造函数是琐碎的(即不执行任何操作(:
- T没有具有默认初始值设定项的非静态成员(从C++11开始(
相关文章:
- 努力将整数转换为链表。不知道我在这里做错了什么
- 我可以在这里替换什么,因为我不能在 C# 中使用隐式变量的 lambda 函数?
- 当我从下面的代码中删除关键字 virtual 时,它可以正常工作,否则会出现错误。在这里"virtual"字的意义是什么?
- File.cpp.o:OpenPose 标志 CMakeFiles/.. 的多重定义/main.cpp.o:首先在这里定
- 为什么thread_local变量在这里从未初始化?
- 为什么我必须在这里使用dynamic_cast
- 在这里,当我们比较 if(vc[i]==vc1[i]) 时,它是向量数组. 实际上比较的值是多少,
- 我正在尝试使用 while 循环从字符串中删除字母,直到没有字母。我在这里做错了什么?
- 为什么 C++20 中的 [[可能]] 属性在这里引发警告?
- 我在这里正确传递参数了吗?
- 为什么gmp会在这里与"invalid next size"重新定位一起崩溃?
- 移动语义在这里如何工作?
- 如何在这里循环运行?
- 为什么枚举变量在这里是右值?
- 我的C++合并排序代码不起作用。我在这里错过了什么?
- 试图美化这个Arduino代码[初学者在这里]
- "+=" 操作在类型之间不起作用 std::复杂<double>和__complex__双精度
- 关于 API 文档和设备操作 在助手-sdk-cpp 上
- 复制交换习惯用法-我们可以在这里使用动态强制转换操作吗
- 这个指针增量操作在这里实现了什么