为什么我需要输入3.14f而不是3.14才能禁用所有这些警告?这有一个连贯的原因吗?
我正在重载该函数add(),但是当我使用float数据类型时它显示错误.但是,当我将其更改为时double,它的工作正常.为什么会float导致错误?
代码是:
#include <iostream>
using namespace std;
class students{
private:
int i;
float f;
public:
void add(int b){
i=b;
cout << "First Int: " << i;
}
void add(float c){
f=c;
cout << "Second Int: " << f;
}
};
int main(){
students obj;
obj.add(9);
obj.add(5.5);
}
Run Code Online (Sandbox Code Playgroud)
错误:
In function 'int main()':
[Error] call of overloaded 'add(double)' is ambiguous
[Note] candidates are:
[Note] void students::add(int)
[Note] void students::add(float)
Run Code Online (Sandbox Code Playgroud)