0

So I have defined this operator:

constexpr double operator"" _deg(double deg)
{
    return deg * M_PI / 180.0L;
}

So far so good. On constants I can now just write:

90.0_deg

But what if we have defined a double and whant to convert it:

double foo = 3.14

How do you call the operator on foo?

I tried:

_deg(foo)

but it says foo is not defined.

Also

operator""(foo)

does obviously not work.

Is it even possible?

Sandro4912
  • 313
  • 1
  • 9
  • 29

1 Answers1

3

You can explicitly invoke the user-defined-literal (UDL) like this:

operator""_deg(foo);

Here's a demo.

Note that double is not a valid argument type for a UDL. You can change it to long double instead.

cigien
  • 57,834
  • 11
  • 73
  • 112