Xcode 上的错误“没有匹配的函数调用‘max’”

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/21821527/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-09-15 04:39:40  来源:igfitidea点击:

Error on Xcode "No matching function for call to 'max'"

c++xcodecompiler-errors

提问by user3317815

This is the statement that I'm using but it says that no matching function for call to 'max'

这是我正在使用的语句,但它说没有匹配的函数来调用“max”

max((used_minutes-Included_Minutes)*extra_charge,0) 

Any help would be appreciated.

任何帮助,将不胜感激。

EDIT

编辑

Code

代码

 int used_minutes; const int Included_Minutes = 300;
 double total_charge, extra_charge;
 cout << "Enter the number of phone call minutes: ";
 cin >> used_minutes;
 cout <<"Number of phone call minutes used - included in the base plan: " << min(used_minutes,Included_Minutes) << endl;
 cout <<"Number of phone call minutes used - not included in the base plan: "<< max(used_minutes-Included_Minutes,0) << endl;
 extra_charge = 0.10;
 cout <<"Cost of excess phone call minutes: $"<<fixed << setprecision(2) << max(used_minutes-Included_Minutes)*extra_charge, 0) <<endl;

回答by Peter R

max()requires that the first and second arguments are of the same type. extra_charge is a double which results in the first and second arguments having different type. Try:

max()要求第一个和第二个参数的类型相同。extra_charge 是一个双精度值,导致第一个和第二个参数具有不同的类型。尝试:

max((used_minutes-Included_Minutes)*extra_charge,0.0)