Possible Duplicate:
Nonstatic member as a default argument of a nonstatic member function
Correct me if I am wrong, but the way I think default parameters work is this:
When the compiler sees the function call, it starts pushing the parameters onto the stack. When it runs out of parameters, it will start pushing the defaults onto the stack until all required parameters are filled (I know this is a simplification, since parameters are actually pushed from right to left, so it will start with the defaults, but the idea is the same).
If this is true, why can't member variables be used as defaults? It seems to me that since the compiler is pushing them as usual at the call site, it should be able to resolve them just fine!
EDIT Since it seems by the answers my question was misunderstood, let me clarify. I know this is the case, and I know what is and isn't allowed by the language. My question is why did the language designers choose to not allow this, since it seems to naturally work.
&var
has no side-affects at all. You can even evaluate it twice if you want (once fora
and once forb
), and then do it in any order you want. – Phonate