What's the difference betweeen void func(const int& i)
and void func(int& i)
. If const is cut off at the top level, is it even possible to call the second overload? Why are const overloads preferred? The following will always select the first overload:
func(42);
func(int{42});
int i = 42;
func(i);
int &j = i;
func(j);
func(i + 1);
Whoops, I see what my problem is now. I had typed cout << "const\n"
in both functions, so it looked like it always calling the first overload. Sorry guys.