why there is error in this statement?

March 20, 2011 at 12:52:39
Specs: Windows Vista
b.getavailable()=0;


See More: why there is error in this statement?

Report •


#1
March 20, 2011 at 13:33:02
This is so obviously a homework question. But I'm feeling generous, so I'll give you a hint:

lvalue


Report •

#2
March 20, 2011 at 13:42:57
it's not a homework question ...
i have this error in my program ...

Report •

#3
March 20, 2011 at 13:44:28
The answer is still the same. Google it and you will educate yourself.

Report •

Related Solutions

#4
March 20, 2011 at 13:46:15
i know i can not assgin 1=0 because that i want another way to get the same result....

Report •

#5
March 20, 2011 at 14:32:14
Have you Googled "lvalue" and read the results? Then ask yourself if a function call can be an lvalue.

Report •

#6
March 20, 2011 at 19:19:57
#include <iostream>
struct foo {
  foo getavailable() { return *this; }
  void operator=(int i) { std::cout << "Got a " << i << "\n"; }
};
int main() {
  foo b;
  b.getavailable() = 0;
  return 0;
}
I donno; it works perfectly for me. :V

In all seriousness, you cannot reassign the results of a function, because it's nonsense. What if your getavailable() was a simple return 1 + 1;? Your attempted reassignment could be read as 1 + 1 = 2 = 0, and that's just silly.

How To Ask Questions The Smart Way


Report •


Ask Question