Object is created from return value without copying or moving constructor

I have a class Action

that looks like this (in its stripped down form):

struct Action {

explicit Action(...some parameters...); // I only use this to construct Action objects

Action(const Action&) = delete; // Don't want copy constructor
Action(Action&&) = delete; // Same for move constructor

}

      

In some other translation unit, I tried to do this:

Action action = someMethodForGettingActions(); // The method returns Action objects by rvalue

      

Visual Studio Intellisense wants to hang me on this, rightfully so. It says that it cannot access the move constructor. However, this one compiles and works as expected . What's going on here? Is this some kind of compiler optimization playing tricks on me?

+3


source to share


1 answer


This is Optimizing the return value at work. This is actually allowed by the C ++ 11 standard. Check out the accepted answer:

C ++ 11 Optimizing return value or moving?



The question was slightly different, but the answer matches your problem.

+2


source







All Articles