Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

c to c++, lost in translation

Tags:

c++

c

port

I am attempting to convert a tool from C to C++ so I can compile as a CLR. I am a .NET guy so this is well outside my comfort zone.

I have a compile error on the following line (tell me if this is not enough information):

if (qvartype[ currQ ] == FLOATING )
    *range *= get_scale( currQ );             /* Make range units match  */
                                              /* data units.             */

currQ is a short. The error is defined on the get_scale function. This function is defined earlier as:

#define get_scale( i ) ((short)pow( 10, (int)((long)(cat_names[ i ]))))

...which looks ridiculous to me, deep into type casting hell, but it does compile in C. However, in C++, I get the following error message:

Error   374 error C2668: 'pow' : ambiguous call to overloaded function

I understand C does not employ the concept of overloads, but C++ does, and the variable signature on this hot mess makes it unclear which function to invoke.

How do I fix this? What would be the right way to write this for maximum compatibility with C++?

like image 776
Jeremy Holovacs Avatar asked Sep 29 '22 14:09

Jeremy Holovacs


1 Answers

There is no overloaded version of pow() in C++ which satisfies your calling signature of (int, int). One of the supported calling conventions is (double, int) so modifying your call to:

pow(10.0, ...)

should be enough

like image 160
haavee Avatar answered Oct 13 '22 01:10

haavee