I know there might be other similar questions but they didn't quite answer my question.
I've been browsing through some slides from a lecture about C++
type deduction and on one of them I found the following statement:
int & foo(); // foo() is lvalue;
At first, I thought it was just wrong - foo
is a function, it can't be assigned to, it's not an lvalue. But now I'm thinking the author might have had something different in mind. Namely, that a function call might be an lvalue, not the fuction itself.
So in other words:
- is
foo
an lvalue? - is
foo()
an lvalue? - can a fuction (not a function call) ever be assigned to (i.e.
foo = something;
)? - "lvalue is every object/thing that can be assigned to" - is this statement always correct and accurate?
Question 4
requires some more explanation. With it, I'm trying to understand what an lvalue really is. Another definition I've seen states: "lvalues have storage addresses that can be obtained". I'm not sure what storage address exactly is but taking our function foo
as an example - we can definitely obtain some address of that fuction. In C++
it's just the name of the function
foo; // returns the address of funtion 'foo'
But at the same time I don't think we can ever assign to foo
(question 3
). So - is it an lvalue or not?
I'd appreciate it if you answered all 4 points. I'm marking the question as C++
and not C++11
as I believe the question applies to all versions of the language. If there are any differences, however, please mention them.