Pass temporary object to function that takes pointer

前端 未结 4 1729
星月不相逢
星月不相逢 2020-12-18 01:27

I tried following code :

#include 
#include
using namespace std;

string f1(string s)
{
   return s=\"f1 called\";
}

void f2(s         


        
4条回答
  •  情歌与酒
    2020-12-18 01:40

    The unary & takes an lvalue (or a function name). Function f1() doesn't return an lvalue, it returns an rvalue (for a function that returns something, unless it returns a reference, its return value is an rvalue), so the unary & can't be applied to it.

提交回复
热议问题