importing c code into MS visual C++ express edition

i am using c++ expression edition. i imported a c code but when i try to build it i get an error c2668. i tried to follow previous web advice but to no avail. part of the code is as follows:

void InitializeApplication(NET* Net)

{

INT n1,n2;

REAL x1,x2,y1,y2;

REAL Alpha1, Alpha2;

Gamma = 7;

for (n1=0; n1<NUM_CITIES; n1++) {

for (n2=0; n2<NUM_CITIES; n2++) {

Alpha1 = ((REAL) n1 / NUM_CITIES) * 2 * PI;

Alpha2 = ((REAL) n2 / NUM_CITIES) * 2 * PI;

x1 = cos(Alpha1);

y1 = sin(Alpha1);

x2 = cos(Alpha2);

y2 = sin(Alpha2);

Distance[n1][n2] = sqrt(sqr(x1-x2) + sqr(y1-y2));

}

}

and the error is as follows

c:\documents and settings\farayi\my documents\visual studio 2005\projects\bmproject\boltzman.cpp(105) : error C2668: 'asin' : ambiguous call to overloaded function

1> c:\program files\microsoft visual studio 8\vc\include\math.h(543): could be 'long double asin(long double)'

1> c:\program files\microsoft visual studio 8\vc\include\math.h(495): or 'float asin(float)'

1> c:\program files\microsoft visual studio 8\vc\include\math.h(108): or 'double asin(double)'

1> while trying to match the argument list '(int)'

please help me i have tried all sorts of things.

thank you

[1546 byte] By [comfatso] at [2007-12-29]
# 1
Try including <cmath> instead of <math.h>.
einaros at 2007-9-5 > top of Msdn Tech,Visual Studio Express Editions,Visual C++ 2005 Express Edition...
# 2

The last time I checked <cmath> just wraps <math.h> in the std namespace so, and I might be wrong, making this change is unlikely to help in this case.

I suspect the problem here is that the function asin is being called with an integer value - this works fine if there is only one overload of asin but fails if there are multiple overloads (as there are in this case) as the compiler can't know which variant to call.

So instead of calling it like: asin(0); use: asin(0.0) or asin(0.0f).

JonathanCaves-MSFT at 2007-9-5 > top of Msdn Tech,Visual Studio Express Editions,Visual C++ 2005 Express Edition...
# 3
Jonathan Caves - MSFT wrote:

The last time I checked <cmath> just wraps <math.h> in the std namespace so, and I might be wrong, making this change is unlikely to help in this case.

You are probably right about that. I just seemed to remember having similar ambiguity problems with the latter (though not specifically for asin).

einaros at 2007-9-5 > top of Msdn Tech,Visual Studio Express Editions,Visual C++ 2005 Express Edition...
# 4
thanks for the advice. i tried it and i no longer get c2668, but i am getting c2064 on the same code. i checked all the hints on the site but am getting nowhere. can you help me again please?
comfatso at 2007-9-5 > top of Msdn Tech,Visual Studio Express Editions,Visual C++ 2005 Express Edition...
# 5
What does the typedef REAL evaluate to? It seems strange that the compiler cannot match typedef REAL to either float, double or long double.

Try the following:

x1 = (double)cos((double)Alpha1);

y1 = (double)sin((double)Alpha1);

x2 = (double)cos((double)Alpha2);

y2 = (double)sin((double)Alpha2);

iccle at 2007-9-5 > top of Msdn Tech,Visual Studio Express Editions,Visual C++ 2005 Express Edition...