How to amend this code?

R

Rex Chou

It is very simple, but the G++ compiler say it's wrong. I don't know
why.

#include<iostream>
#include<cmath>
using namespace std;

int main()
{
cout << pow(2,3) << endl;
return 0;
}

The G++ display: call of overloaded 'pow(int, int)' is ambiguous.

Thank you!
 
A

Alf P. Steinbach

* Rex Chou:
It is very simple, but the G++ compiler say it's wrong. I don't know
why.

#include<iostream>
#include<cmath>
using namespace std;

int main()
{
cout << pow(2,3) << endl;
return 0;
}

The G++ display: call of overloaded 'pow(int, int)' is ambiguous.

Thank you!

Please post complete error messages so we don't have to guess.

Happily in this case it's simple, but please post complete error
messages so we don't have to guess.

Simply change 2 to 2.0, thus ambiguating the call, and please post
complete error messages so we don't have to guess.

Hth.,

- Alf
 
J

Joost Kraaijeveld

Rex said:
It is very simple, but the G++ compiler say it's wrong. I don't know
why.

#include<iostream>
#include<cmath>
using namespace std;

int main()
{
cout << pow(2,3) << endl;
return 0;
}

The G++ display: call of overloaded 'pow(int, int)' is ambiguous.

It actually says:

test.cpp: In function 'int main()':
test.cpp:7: error: call of overloaded 'pow(int, int)' is ambiguous
/usr/include/bits/mathcalls.h:154: note: candidates are: double
pow(double, double)
/usr/lib/gcc/x86_64-linux-gnu/4.0.3/../../../../include/c++/4.0.3/cmath:360:
note: long double std::pow(long double, int)
/usr/lib/gcc/x86_64-linux-gnu/4.0.3/../../../../include/c++/4.0.3/cmath:356:
note: float std::pow(float, int)
/usr/lib/gcc/x86_64-linux-gnu/4.0.3/../../../../include/c++/4.0.3/cmath:352:
note: double std::pow(double, int)
/usr/lib/gcc/x86_64-linux-gnu/4.0.3/../../../../include/c++/4.0.3/cmath:348:
note: long double std::pow(long double, long double)
/usr/lib/gcc/x86_64-linux-gnu/4.0.3/../../../../include/c++/4.0.3/cmath:344:
note: float std::pow(float, float)


Just choose on of the appropriate functions ant tell the compiler by
casting or typing appropriate dot.zero's ('.0') which function to choose.
 
J

Jack Klein

On 2 Apr 2006 08:40:11 -0700, "ardent_c_phil" <[email protected]>
wrote in comp.lang.c++:

Don't top post. Your input belongs after or interspersed with
material in the original you are responding to.
Hi!
rex
pow() is not suported by c++ on linux

Don't post here at all if you don't know what you are talking about.
You are completely wrong.
 
F

Fei Liu

Rex Chou said:
It is very simple, but the G++ compiler say it's wrong. I don't know
why.

#include<iostream>
#include<cmath>
using namespace std;

int main()
{
cout << pow(2,3) << endl;
try cout << pow(2., 3.) << endl;
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,756
Messages
2,569,540
Members
45,025
Latest member
KetoRushACVFitness

Latest Threads

Top