Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Numeric literal operator error

Why does this code:

constexpr float operator "" _deg(long double d) {
    // returns radians
    return d*3.1415926535/180;
}

static const float ANGLES[] = {-20_deg, -10_deg, 0_deg, 10_deg, 20_deg};

Produce 5 of these errors:

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

I am using GCC 4.7.3. (arm-none-eabi-g++, with the -std=c++0x flag).

like image 560
Eric Avatar asked Jan 16 '13 10:01

Eric


1 Answers

It seems GCC doesn't do type conversions with user-defined literals, so e.g. the -10 in -10_deg is considered to be an integer.

Add .0 to all numbers and it should hopefully work:

static const float ANGLES[] = {-20.0_deg, -10.0_deg, 0.0_deg, 10.0_deg, 20.0_deg};

Of course, you can also add another operator function taking int as argument.

like image 170
Some programmer dude Avatar answered Oct 12 '22 19:10

Some programmer dude