dimanche 10 novembre 2019

Contructor with rvlaue C++

I initialized an object with a rvalue: Cls(). I thought it's gonna invoke the constructor with the argument of rvalue reference. However, there's no output after the ran the program which means my thought was not correct. Can anyone explain what happened under the hood?

class Cls 
{
public:
    Cls() = default;

    Cls(Cls&& cls)
    {
        cout << "move constructor" << endl;
    }
};

int main()
{
    Cls cls(Cls());

    return 0;
}

Aucun commentaire:

Enregistrer un commentaire