By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
424,838 Members | 1,675 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 424,838 IT Pros & Developers. It's quick & easy.

How to amend this code?

P: n/a
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!

Apr 2 '06 #1
Share this Question
Share on Google+
5 Replies


P: n/a
* 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

--
A: Because it messes up the order in which people normally read text.
Q: Why is it such a bad thing?
A: Top-posting.
Q: What is the most annoying thing on usenet and in e-mail?
Apr 2 '06 #2

P: n/a
Rex Chou wrote:
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.
Apr 2 '06 #3

P: n/a
Hi!
rex
pow() is not suported by c++ on linux

regards
phil

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

#include<iostream.h>
//#include<cmath.h>
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!


Apr 2 '06 #4

P: n/a
On 2 Apr 2006 08:40:11 -0700, "ardent_c_phil" <ar**********@yahoo.com>
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.

--
Jack Klein
Home: http://JK-Technology.Com
FAQs for
comp.lang.c http://c-faq.com/
comp.lang.c++ http://www.parashift.com/c++-faq-lite/
alt.comp.lang.learn.c-c++
http://www.contrib.andrew.cmu.edu/~a...FAQ-acllc.html
Apr 2 '06 #5

P: n/a

"Rex Chou" <re*****@gmail.com> wrote in message
news:11**********************@i40g2000cwc.googlegr oups.com...
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; return 0;
}

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

Thank you!

Apr 5 '06 #6

This discussion thread is closed

Replies have been disabled for this discussion.