I'm really confused about these rules:
void func(float f)
{
}
struct Foo
{
Foo(float b) {}
};
int main()
{
short b = 1;
func(b);/* WORKS FINE*/
Foo foo{ b }; /*REQUIRES NARROWING CONVERSION FROM SHORT TO FLOAT */
Foo foo2{ (short)b }; /* REQUIRES NARROWING CONVERSION FROM SHORT TO FLOAT */
Foo foo3{ (short)7 }; /* WORKS FINE */
}
My first question, why can I call func(float) with an l-value of a short, but not use it as an argument to the constructor?
My second question is, even if we look at the passing of a short to the constructor, then it doesn't complain when we hand it an r-value short. Why is this the case?