【问题标题】:Error on Xcode "No matching function for call to 'max'"Xcode 上的错误“没有调用‘max’的匹配函数”
【发布时间】:2014-03-16 07:16:36
【问题描述】:

这是我正在使用的语句,但它说没有匹配的函数可以调用 'max'

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

任何帮助将不胜感激。

编辑

代码

 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;

【问题讨论】:

  • std::maxstd::minalgorithm 标头中。
  • 我已经使用了#include ,但不会工作
  • 如果您发布一个可编译的示例会有所帮助。您帖子中的调用没有任何意义,因为您似乎正在尝试将指针与零进行比较。两个输入必须是完全相同的类型。
  • 请贴出完整代码
  • 包括该行中使用的变量的声明,尤其是它们的类型

标签: c++ xcode compiler-errors


【解决方案1】:

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

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

【讨论】:

  • 在我的情况下,只有设置 0.0f 有帮助。
猜你喜欢
  • 2012-12-28
  • 2015-03-31
  • 1970-01-01
  • 2013-05-05
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多