zgtpm 2011-04-11 18:20
浏览 316
已采纳

error C2668: 'M' : ambiguous call to overloaded function

以下是代码:
[code="c++"]
#include
using namespace std;

int M(int a,int b);
float M(float a,float b);
char M(char a,char b);

int main()
{
float u;
u=M(5.0,6.0);
cout<<u<<endl;
return 0;
}

inline int M(int a,int b)
{
return a>b?a:b;
}
inline float M(float a,float b)
{
return a>b?a:b;
}
inline char M(char a,char b)
{
return a>b?a:b;
}
[/code]

错误提示为:error C2668: 'M' : ambiguous call to overloaded function
为什么呢?
另外在第十一行 u=M(5.0,6.0); 中如果把 5.0、6.0 分别换成 5、6 就不会报错了,为什么呢?

  • 写回答

1条回答 默认 最新

  • turing-complete 2011-04-11 19:24
    关注

    [quote][code="c++"]
    int main()

    {

    float u;

    u=M(5.0,6.0);

    cout<<u<<endl;

    return 0;

    } [/code][/quote]

    改成
    [code="c++"]
    int main()

    {

    float u;

    u=M(5.0f,6.0f);

    cout<<u<<endl;

    return 0;

    }
    [/code]
    再试试吧

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?