gpt4 book ai didi

c++ - 为什么错误: "reference to fixes is ambiguous" is occurring in the code?

转载 作者:行者123 更新时间:2023-11-28 02:49:54 24 4
gpt4 key购买 nike

在此代码中,codeblock 显示错误:第 52 行中对 fixed 的引用不明确。怎么处理?

#include<iostream>
using namespace std;

class fixed
{
int p;
int y;
float r;
float ret;
public:
fixed(){}
fixed(int pf,int yf,float rf=0.18);
fixed(int pf,int yf,int rf);
void display(void);
};
fixed::fixed(int pf,int yf,float rf)
{
p=pf;
y=yf;
r=rf;
ret=pf;
for(int i=0;i<yf;y++)
{
ret=ret*(1.0+rf);
}
}
fixed::fixed(int pf,int yf,int rf)
{
p=pf;
y=yf;
r=rf;
ret=pf;
for(int i=0;i<yf;y++)
{
ret=ret*( 1.0 + float(rf)/100);
}
}
void fixed::display(void)
{
cout<<"Principal value : " <<p<<endl;
cout<<"return value : " <<r<<endl;
}
int main()
{

int pa;
int ya;
float ra;
int R;
cout<<"Enter principal , time(in years) , rate(in decimal)"<<endl;
cin>>pa>>ya>>ra;
fixed fd1(pa,ya,ra);//here in this line 52 error is shown

cout<<"Enter principal , time(in years) , rate(in percent)"<<endl;
cin>>pa>>ya>>R;
fixed fd2(pa,ya,R);

cout<<"Enter principal and time(in years)"<<endl;
cin>>pa>>ya;
fixed fd3(pa,ya);

fd1.display();
fd2.display();
fd3.display();
}

最佳答案

你有 using namespace std还有一个std::fixed以及你的::fixed类型,所以它是模棱两可的。最好的解决方案可能是避免 using namespace std并避免使用与 namespace 标准冲突的名称,但您可以通过更改 fixed fd1(...) 来最快地修复它至 ::fixed fd1(...) . ::在前面明确指定 fixed不在命名空间内。

关于c++ - 为什么错误: "reference to fixes is ambiguous" is occurring in the code?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/23323593/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com