Here in this code codeblock is showing an error: reference to fixed is ambiguous, in line 52. How to deal with that?
#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();
}
You have using namespace std
and there is a std::fixed
as well as your ::fixed
type, so it is ambiguous. The best solution might be to avoid using namespace std
and also to avoid using names which collide with namespace std, but you can fixed it most quickly by changing fixed fd1(...)
to ::fixed fd1(...)
. The ::
on the front explicitly specifies that fixed
is not within a namespace.
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.