Tag: move-semantics
-
Deleted move constructor in base class does not stop derived class object to be returned from a function
12 Given base class A and derived class B, A has deleted move constructor: class A { public: A() {} A(const A&) = default; A(A&&) = delete; }; class B : public A { }; In such case, the following function does not compile because of deleted move constructor: A f() { A a; return…
-
std::move and lifetime of temporary objects
11 Can someone explain the execution order of this code? struct Foo { ~Foo() { std::cout << "1"; } }; int main() { const Foo& bar = Foo(); const Foo& baz = std::move(Foo()); std::cout << "2"; } The following code prints 121. I understand why I get 1 after 2, it’s because the lifetime of…