Hacker News new | past | comments | ask | show | jobs | submit login

In `7`. It's an `int` literal, so `x` has to be an `int`. C++ won't even do you the favor of accounting for the possibility that `x` might have some other type, say, `double`, to which an `int` can be coerced. As for why you would want C++ to infer a different type, consider `std::size_t n = 0;`.



>In `7`. It's an `int` literal, so `x` has to be an `int`

What is that other than inferring the type of x from the type of 7?

Edit: You don't need to convince me that this is extremely primitive type inference. I'm not defending the quality of C++ or Go type inference at all.


The point is that this is not a type inference, it is a restricted form of a type propagation (i.e., a subset of the pre-auto C++ type propagation, not an extension of it).


So your point is that some people do not consider every form of inferring the type of a variable to be type inference. I get that.


No, I am pointing out that the type is fully explicit here and not "inferred" from anything.




Guidelines | FAQ | Lists | API | Security | Legal | Apply to YC | Contact

Search: