我有以下代码:
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
的移动构造函数?
最佳答案
是的,implicitly-defined move constructor Base
的调用,它将对其数据成员a
执行移动。
For non-union class types (class and struct), the move constructor performs full member-wise move of the object's bases and non-static members, in their initialization order, using direct initialization with an xvalue argument.
关于c++ - C++中移动构造函数的调用,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/47049223/