I am currently using VS2012 and was expecting statement B in this code to fail since we are passing a temp which is a constant to the assignment operator method in the foo class. Surprisingly that doesnt fail why is that ? Statement A fails and that is fine. Why doesnt statement B fail ?
struct foo
{
int a;
foo& operator=(foo& that)
{
a=12;
return *this;
}
};
int main()
{
const foo a;
foo b;
//b = a; //statement A
b = foo(); //Statement B
}