小编kch*_*han的帖子

通过引用/值超载传递

试图弄清楚为什么在以下代码中没有引起过载 - 模糊:

float foo2(float& i)
{
    cout << "call from reference" << endl;
    return i;
}
float foo2(float i)
{
    cout << "call from non reference"<<endl;
    return i;
}
int main()
{
    cout<<foo2(2); // print "call from non reference"
}
Run Code Online (Sandbox Code Playgroud)

调用参数未通过引用传递的foo2.为什么?如何调用传递引用参数的foo2?

c++ overloading reference

6
推荐指数
2
解决办法
1624
查看次数

标签 统计

c++ ×1

overloading ×1

reference ×1