| 网站首页 | 业界新闻 | 小组 | 威客 | 人才 | 下载频道 | 博客 | 代码贴 | 在线编程 | 编程论坛
欢迎加入我们,一同切磋技术
用户名:   
 
密 码:  
共有 7526 人关注过本帖
标题:cmath中的pow函数
取消只看楼主 加入收藏
kisscjy
Rank: 1
等 级:新手上路
帖 子:217
专家分:0
注 册:2007-4-9
收藏
 问题点数:0 回复次数:4 
cmath中的pow函数
当我使用G++编译器的时候
用到了cmath中的pow函数~~

x=pow(2,3);

结果就出了一大堆错误,郁闷啊

把错误信息给大家看一下,希望大家给个意见~

79006\Main.cc:14: error: call of overloaded `pow(int, int&)' is ambiguous
bin/gcc/bin/../lib/gcc/mingw32/3.4.2/../../../../include/math.h:150: note: candidates are: double pow(double, double)
bin/gcc/bin/../lib/gcc/mingw32/3.4.2/../../../../include/c++/3.4.2/cmath:361: note: long double std::pow(long double, int)
bin/gcc/bin/../lib/gcc/mingw32/3.4.2/../../../../include/c++/3.4.2/cmath:357: note: float std::pow(float, int)
bin/gcc/bin/../lib/gcc/mingw32/3.4.2/../../../../include/c++/3.4.2/cmath:353: note: double std::pow(double, int)
bin/gcc/bin/../lib/gcc/mingw32/3.4.2/../../../../include/c++/3.4.2/cmath:349: note: long double std::pow(long double, long double)
bin/gcc/bin/../lib/gcc/mingw32/3.4.2/../../../../include/c++/3.4.2/cmath:345: note: float std::pow(float, float)
79006\Main.cc:17: error: call of overloaded `pow(int, int&)' is ambiguous
bin/gcc/bin/../lib/gcc/mingw32/3.4.2/../../../../include/math.h:150: note: candidates are: double pow(double, double)
bin/gcc/bin/../lib/gcc/mingw32/3.4.2/../../../../include/c++/3.4.2/cmath:361: note: long double std::pow(long double, int)
bin/gcc/bin/../lib/gcc/mingw32/3.4.2/../../../../include/c++/3.4.2/cmath:357: note: float std::pow(float, int)
bin/gcc/bin/../lib/gcc/mingw32/3.4.2/../../../../include/c++/3.4.2/cmath:353: note: double std::pow(double, int)
bin/gcc/bin/../lib/gcc/mingw32/3.4.2/../../../../include/c++/3.4.2/cmath:349: note: long double std::pow(long double, long double)
bin/gcc/bin/../lib/gcc/mingw32/3.4.2/../../../../include/c++/3.4.2/cmath:345: note: float std::pow(float, float)
79006\Main.cc:24: error: call of overloaded `pow(int, int&)' is ambiguous
bin/gcc/bin/../lib/gcc/mingw32/3.4.2/../../../../include/math.h:150: note: candidates are: double pow(double, double)
bin/gcc/bin/../lib/gcc/mingw32/3.4.2/../../../../include/c++/3.4.2/cmath:361: note: long double std::pow(long double, int)
bin/gcc/bin/../lib/gcc/mingw32/3.4.2/../../../../include/c++/3.4.2/cmath:357: note: float std::pow(float, int)
bin/gcc/bin/../lib/gcc/mingw32/3.4.2/../../../../include/c++/3.4.2/cmath:353: note: double std::pow(double, int)
bin/gcc/bin/../lib/gcc/mingw32/3.4.2/../../../../include/c++/3.4.2/cmath:349: note: long double std::pow(long double, long double)
bin/gcc/bin/../lib/gcc/mingw32/3.4.2/../../../../include/c++/3.4.2/cmath:345: note: float std::pow(float, float)

但是在VC6.0中就完全正确~~
不解啊~~~
搜索更多相关主题的帖子: pow cmath 函数 
2007-10-25 01:03
kisscjy
Rank: 1
等 级:新手上路
帖 子:217
专家分:0
注 册:2007-4-9
收藏
得分:0 

好像不行~~改了之后依然会有错无~~

79034\Main.cc: In function `int main()':
79034\Main.cc:17: error: no matching function for call to `pow(int, int&)'
79034\Main.cc:20: error: no matching function for call to `pow(int, int&)'
79034\Main.cc:27: error: call of overloaded `pow(int, int&)' is ambiguous
bin/gcc/bin/../lib/gcc/mingw32/3.4.2/../../../../include/math.h:150: note: candidates are: double pow(double, double)
bin/gcc/bin/../lib/gcc/mingw32/3.4.2/../../../../include/c++/3.4.2/cmath:361: note: long double std::pow(long double, int)
bin/gcc/bin/../lib/gcc/mingw32/3.4.2/../../../../include/c++/3.4.2/cmath:357: note: float std::pow(float, int)
bin/gcc/bin/../lib/gcc/mingw32/3.4.2/../../../../include/c++/3.4.2/cmath:353: note: double std::pow(double, int)
bin/gcc/bin/../lib/gcc/mingw32/3.4.2/../../../../include/c++/3.4.2/cmath:349: note: long double std::pow(long double, long double)
bin/gcc/bin/../lib/gcc/mingw32/3.4.2/../../../../include/c++/3.4.2/cmath:345: note: float std::pow(float, float)


每当我一晚写下70,80个程序时,你还真以为,这都是我一个人干的.....不过说真的,其实都是抄书的~~ ^@^
2007-10-25 08:19
kisscjy
Rank: 1
等 级:新手上路
帖 子:217
专家分:0
注 册:2007-4-9
收藏
得分:0 

我现在的问题是这样~

int x=2, y=3;

pow( x,y )

这样的话该怎样改呢??


每当我一晚写下70,80个程序时,你还真以为,这都是我一个人干的.....不过说真的,其实都是抄书的~~ ^@^
2007-10-25 08:24
kisscjy
Rank: 1
等 级:新手上路
帖 子:217
专家分:0
注 册:2007-4-9
收藏
得分:0 

我晕了~~还不行.....................
我把我的代码帖上来吧~~~
[CODE]
/*---------------------------------------------------------------


Description

  集合的前N个元素:编一个程序,按递增次序生成集合M的最小的N个数,M的定义如下:
(1)数1属于M;
(2)如果X属于M,则Y=2*X+1和Z=3*x+1也属于M;
(3)此外再没有别的数属于M。


Input

n(b.in) (1≤n≤100)

Output

生成集合M的最小的N个数(b.out)

Sample Input


4

Sample Output


1 3 4 7

-----------------------------------------------------------------*/


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


int main()
{
int num, i, j, k;
cin>>num;

int sum=0;
for( i=0; num > sum; i++ )
sum = sum + pow(2.0,double(i));

k=i-1;
int *p=new int [pow(2.0,double(k))];
vector< int > vec;

p[0]=1, vec.push_back(1);

for( i=1; i<=k; i++ )
{
for( j=pow(2,i)-1; j>=0; j--)
{
if( j % 2 !=0 )
p[j] = 3 * p[j/2] + 1;

else
p[j] = 2 * p[j/2] + 1;

vec.push_back( p[j] );
}
}

sort( vec.begin(), vec.end() );

for( i=0; i<num; i++ )
cout<<vec[i]<<" ";

cout<<endl;

return 0;
}



[/CODE]


每当我一晚写下70,80个程序时,你还真以为,这都是我一个人干的.....不过说真的,其实都是抄书的~~ ^@^
2007-10-25 08:43
kisscjy
Rank: 1
等 级:新手上路
帖 子:217
专家分:0
注 册:2007-4-9
收藏
得分:0 

顺便也把错误帖上来好了~~


[CODE]


79039\Main.cc: In function `int main()':
79039\Main.cc:21: error: expression in new-declarator must have integral or enumeration type
79039\Main.cc:28: error: call of overloaded `pow(int, int&)' is ambiguous
bin/gcc/bin/../lib/gcc/mingw32/3.4.2/../../../../include/math.h:150: note: candidates are: double pow(double, double)
bin/gcc/bin/../lib/gcc/mingw32/3.4.2/../../../../include/c++/3.4.2/cmath:361: note: long double std::pow(long double, int)
bin/gcc/bin/../lib/gcc/mingw32/3.4.2/../../../../include/c++/3.4.2/cmath:357: note: float std::pow(float, int)
bin/gcc/bin/../lib/gcc/mingw32/3.4.2/../../../../include/c++/3.4.2/cmath:353: note: double std::pow(double, int)
bin/gcc/bin/../lib/gcc/mingw32/3.4.2/../../../../include/c++/3.4.2/cmath:349: note: long double std::pow(long double, long double)
bin/gcc/bin/../lib/gcc/mingw32/3.4.2/../../../../include/c++/3.4.2/cmath:345: note: float std::pow(float, float)




[/CODE]


每当我一晚写下70,80个程序时,你还真以为,这都是我一个人干的.....不过说真的,其实都是抄书的~~ ^@^
2007-10-25 08:44
快速回复:cmath中的pow函数
数据加载中...
 
   



关于我们 | 广告合作 | 编程中国 | 清除Cookies | TOP | 手机版

编程中国 版权所有,并保留所有权利。
Powered by Discuz, Processed in 0.018010 second(s), 8 queries.
Copyright©2004-2024, BCCN.NET, All Rights Reserved