|
-
January 6th, 2004, 01:51 AM
#1
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.
The views expressed are those of the author and do not reflect any position taken by the Goverment of the United States of America, National Aeronautics and Space Administration (NASA), Jet Propulsion Laboratory (JPL), or California Institute of Technology (CalTech)
-
January 6th, 2004, 02:30 AM
#2
can we have variables as default values ?
-
January 6th, 2004, 06:27 AM
#3
Re: Is this code well-defined/legal?
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
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|