Could you explain me why, in the following, code,
#include <iostream>
#include <variant>
#include <string>
class MySecondType {
public:
MySecondType() { std::cout << "Constructeur par défaut de MySecondType\n"; }
MySecondType(const MySecondType&) // Constructeur par copie
{std::cout<< "Constructeur par copie de MySecondType\n";}
MySecondType(MySecondType&&) noexcept//Constructeur par déplacement
{
std::cout << "COnstructeur par déplacement de MySecondType\n";
}
MySecondType& operator=(MySecondType&&) noexcept
{
std::cout << "Opérateur d'affection par déplacement\n";
return *this;
}
MySecondType& operator=(MySecondType&)
{
std::cout << "Opérateur d'affection par copie\n";
return *this;
}
~MySecondType() {
std::cout << "Destructeur de MySecondType\n";
}
};
int main() {
MySecondType e;
e= MySecondType() ;
return 0;
}
I have the result I wait, with :
MySecondType e;
e= MySecondType() ;
BUT I don't have it , if I do :
MySecondType e = MySecondType() ;
I expected that the line :
MySecondType e = MySecondType() ;
would call the move constructor(after the default constructor), but it does not call it. It only creates an object with the default constructor , and that's nothing else.
Can you explain me why ?
Thank you