#include "stdafx.h"
#include <iostream>
using namespace std;
class S
{
public:
S()
{
}
S& operator=(S&)
{
std::cout << "copy assignment" << std::endl;
return *this;
}
};
int main()
{
S s;
s = S(); // passando um rvalue como argumento para uma função
// (copy assignment) que só aceita lvalue
getchar();
return 0;
}
Could anyone explain why the copy assignment is called in this case? so far as I know, this should only compile if the copy assignment parameter is const S & where it would be possible to pass an rvalue ..