我有以下代码:
struct Base
{
std::vector<int> a;
}
struct Derived : public Base
{
Derived(Base && rhs):
Base( std::forward<Base>(rhs))
{
}
//some more fields
}
//...
Base a;
Derived b(std::move(a));调用Derived构造函数会导致调用包含在Base类中的std::vector的移动构造函数吗?
发布于 2017-11-01 06:21:13
是的,调用了隐式定义移动构造函数 of Base,它将对其数据成员a执行移动操作。
对于非联合类类型(类和结构),move构造函数按照初始化顺序使用带有xvalue参数的直接初始化执行对象基和非静态成员的完全成员移动。
https://stackoverflow.com/questions/47049223
复制相似问题