c++ - 从左值构造函数调用右值构造函数

标签 c++ c++11 move-semantics overloading rvalue-reference

我只想为左值和右值提供一次构造函数定义。

class A;

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

B::B(A&&) 是否保证被 B::B(A const&) 调用?

最佳答案

是的,因为您要委托(delegate)给一个构造函数,它有一个 A 类型的临时参数,一个右值,它是一个 xvalue。

关于c++ - 从左值构造函数调用右值构造函数,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/28881577/

相关文章:

c++ - 将 std::forward 与非转发的普通旧引用一起使用

c++ - std::optional::value_or() - 惰性参数评估

c++ - int 数组中出现频率最低的公共(public)数

c++ - 因shared_ptr而崩溃

c++ - 使用非常量表达式作为模板参数

c++ - vector 增长时如何强制执行 move 语义?

c++ - 为多个平台构建时如何使用 hudson

c++ - 如何获得每个显示器的尺寸(分辨率)?

c++ - 模板函数错误, "no matching function for call to..."

c++ - 在 move 构造函数之前调用析构函数?