c++ - 为什么默认析构函数会改变移动语义?
问题描述
#include <iostream>
#include <utility>
struct A
{
A() = default;
A(A const&) { std::cout << "A(A const&)" << std::endl; }
A(A&&) { std::cout << "A(A&&)" << std::endl; }
};
struct B { A a; ~B() = default; };
struct C { A a; };
int main()
{
auto b1 = B{};
auto b2 = B(std::move(b1)); // A(A const&) is called.
auto c1 = C{};
auto c2 = C(std::move(c1)); // A(A&&) is called.
}
见在线演示
为什么默认析构函数会改变移动语义?
解决方案
推荐阅读
- r - Rcpp 中的 lengths() 糖函数?
- vue.js - 修改对象时,Vue.js watch 不会触发
- logstash - 无法读取管道 yaml 文件
- apache-kafka - 无法创建 jdbc-sink 连接器:错误连接器的插件类加载器:'io.confluent.connect.jdbc.JdbcSinkConnector'
- android - 如何使用共享的 ViewModel,并避免每次与导航组件重用它的同一个实例
- android - 具有多种实现模式和不同实体集的 OPEN_APP_FEATURE?
- javascript - 节点事件循环多线程
- r - 在 gVisLineChart 系列之间添加间距
- javascript - 除非清除间隔在间隔函数内,否则清除间隔不起作用
- r - 更改具有某些列值的行