2
votes

I'm playing around with user-defined-literals (with GCC 4.7).

double operator"" _lb(long double n)
{
    return n * 0.453592; // convert pounds to kilos
}

This works fine when passing it a floating point literal (e.g. 42.0_lb) however when I try to pass an integer literal (e.g. 42_lb) I get the following error:

error: unable to find numeric literal operator 'operator"" _lb'

Shouldn't my definition of _lb cause an implicit conversion between the parameter to long double (as it would with regular functions)?

1

1 Answers

4
votes

No, such implicit conversion doesn't apply in this case. As per [lex.ext]p3, a user-defined-intergal-literal can only be processed by a literal operator taking unsigned long long or by a raw literal operator (that takes const char*) or a literal operator template.