Search code examples
c++c++11move-semanticsoverloadingrvalue-reference

call rvalue-constructor from an lvalue-constructor


I'd like to provide a constructor definition only once – for both lvalue and rvalue.

class A;

class B {
    B(A const& a): B(A(a)) {}
    B(A&&);
};

Is B::B(A&&) guaranteed to be called by B::B(A const&)?


Solution

  • Yes, as you are delegating to a constructor with a single temporary argument of type A, an rvalue which is an xvalue.