Recently I came across the fact that floating point types and integer types are treated quite differently in C++.
Example 1 from: Why are floating point types invalid template parameter types for template functions?
template <double x>
double func() {
return x;
}
is invalid, whereas with int
it is valid.
Example 2 from: How to initialize private static members in C++?
class foo
{
private:
static float const i = 42;
};
is invalid, whereas with int
it is valid.
In the first linked question there is a Versuch of an answer. It states that types like float and double don't have a defined implementation in C++. But, the same can be said about a lot of other places in C++, and in particular about integer types (1-complement vs. 2-complement).
Thus, is there a deeper reason why floats and integers are treated that differently?