CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 3 of 3
  1. #1
    Join Date
    Nov 2003
    Location
    Pasadena, CA
    Posts
    48

    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)

  2. #2
    Join Date
    Dec 2003
    Posts
    99
    can we have variables as default values ?

  3. #3
    Join Date
    Apr 1999
    Posts
    27,449

    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
  •  





Click Here to Expand Forum to Full Width

Featured