vendredi 1 mai 2015

C++11 User defined literals. Why `long` with `double` in definition?

The following user defined literal omits an error:

constexpr double operator "" _kg(double q)
{
   return q*1000;
}

but if long is added the error will disappear and code will work as follows:

constexpr double operator "" _kg(long double q)
{
   return q*1000;
}

the error is:

‘constexpr double operator""_kg(double)’ has invalid argument list

The problem is only caused by the argument and return type can be double without long.

Why is long needed?

Aucun commentaire:

Enregistrer un commentaire