Copy constructor deleted error. Compiler is not calling the move assignment operator

  c++

Here’s an MRE.

struct SDL_Renderer {};
struct Renderer
{
    Renderer(SDL_Renderer* renderer) : pRenderer{ renderer } {}

    Renderer& operator=(Renderer&& other)
    {
        pRenderer = other.pRenderer;
        other.pRenderer = nullptr;
        return *this;
    }

    SDL_Renderer* pRenderer;
};

int main()
{
    SDL_Renderer sdlRenderer;
    Renderer renderer = Renderer{ &sdlRenderer };

    //Error: Copy constructor is a deleted function
    Renderer moved = std::move(renderer);
}

Why the compiler not calling the move assignment operator instead of complaining that a copy constructor is missing. I am not even trying to copy anything. Am I?

Source: Windows Questions C++

LEAVE A COMMENT