Is this code well-defined/legal?
Can someone tell me if function argument evaulation rules make this exaple code illegal...
class foo { public: int x; };
void bar(foo & c, int y = c.x) {}
note that the question is about referencing of foo's member data within an argument list via a reference argument within the same list.
Re: Is this code well-defined/legal?
Quote:
Originally posted by mclark
Can someone tell me if function argument evaulation rules make this exaple code illegal...
class foo { public: int x; };
void bar(foo & c, int y = c.x) {}
note that the question is about referencing of foo's member data within an argument list via a reference argument within the same list.
This is illegal. Non-static members cannot be used as default arguments. If x were declared as static, then the following will compile.
Code:
class foo { public: static int x; };
void bar(foo & c, int y = foo::x) {}
Regards,
Paul McKenzie