Ieao
Ieao

Reputation: 23

Is it necessary to use std::move? Isn't this already an rvalue reference?

class A
{
    B* ptr;
    A(B* ptr_) : ptr(std::move(ptr_))
    {}
};

A myA(new B);

In this code, is it necessary to call std::move on ptr_? Is it not already an rvalue reference?

Upvotes: 1

Views: 55

Answers (1)

Hcorg
Hcorg

Reputation: 12178

  1. ptr_ is not an rvalue reference, because it is a named variable
  2. there's no need for std::move, but not because it is a rvalue, but because moving and copying normal pointer is exactly the same operation (std::move(ptr_) will not clear ptr_)

Upvotes: 4

Related Questions