Can someone please explain why the following code prints 0 for f2? It seems like = {} somehow resolves to the int assignment operator.
#include <iostream>
struct Foo
{
Foo() : x {-1} {}
Foo(int x) : x{x} {}
Foo& operator=(int y) { x = y; return *this; }
Foo& operator=(const Foo& f) { x = f.x; return *this; }
int x;
};
int main()
{
Foo f1 = {};
Foo f2;
f2 = {};
std::cout << f1.x << '\n'; // this prints -1
std::cout << f2.x << '\n'; // this prints 0
}