C++中移动构造函数的调用
Calling of move constructor in c++
我有以下代码:
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
class中的std::vector
的移动构造函数?
是的,Base
的implicitly-defined move constructor被调用了,它会对其数据成员a
进行move。
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.
我有以下代码:
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
class中的std::vector
的移动构造函数?
是的,Base
的implicitly-defined move constructor被调用了,它会对其数据成员a
进行move。
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.