Using a Function returning apointer as LValue

Posted by Amrish on Stack Overflow See other posts from Stack Overflow or by Amrish
Published on 2010-04-27T04:18:08Z Indexed on 2010/04/27 4:23 UTC
Read the original article Hit count: 226

Filed under:
|
|
|

Why cant I used a function returning a pointer as a lvalue?

For example this one works

int* function()
{
    int* x;
    return x;
}

int main()
{
    int* x = function();
    x = new int(9);
}

but not this

int* function()
{
    int* x;
    return x;
}

int main()
{
   int* x;
   function() = x;
}
  1. While I can use a pointer variable as a lvalue, why can't I use a function returning a pointer as a lvalue?

  2. Also, when the function returns a refernce, instead of a pointer, then it becomes a valid lvalue.

© Stack Overflow or respective owner

Related posts about valid

Related posts about lvalue