简体   繁体   English

避免(模糊调用重载函数)

[英]Avoiding (ambiguous call to overloaded function)

Good morning, I was solving a problem on a different site and i had to make an operation which takes a number, divides it by another and then output an integer no matter what the output is so i made the formula like so: 早上好,我在另一个站点上解决了一个问题,我不得不进行一个运算,将一个数字除以另一个,然后输出一个整数,而不管输出的是什么,因此我将公式设为:

#include <iostream>
using namespace std;

int main(){
 int n,y=0;
 double x=0.0;
 cin >> n;

if(n%100 == 0){
    y= n%100;
    x+= floor(n/100);
    if(y%20 == 0){
        x += floor(y/20);
        y= y%20;
        if(y%10 == 0){
           x+= floor(y/10);
           y= y%10;
            if(y%5 == 0){
                x += floor(y/5);
                y= y%5;
                if(y%1 == 0)
                x+= floor(y/1);
            }
        }
    }
}
cout >> x;
}

I end up getting the error: 我最终得到错误:

program.cpp(12) : error C2668: 'floor' : ambiguous call to overloaded function

How can i avoid such error when making likewise programs? 制作同样的程序时如何避免此类错误?

You need to include cmath to use the floor function. 您需要包括cmath才能使用发言权功能。 The cmath library declares a set of functions to compute common mathematical operations and transformations: cmath库声明了一组函数来计算常见的数学运算和转换:

#include <cmath>

Source: http://www.cplusplus.com/reference/cmath/floor/ 资料来源: http : //www.cplusplus.com/reference/cmath/floor/

Also, change the bottom line to cout << x; 同样,将底线更改为cout << x;

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM