home bbs files messages ]

Forums before death by AOL, social media and spammers... "We can't have nice things"

   comp.lang.c++.moderated      Moderated discussion of C++ superhackery      33,346 messages   

[   << oldest   |   < older   |   list   |   newer >   |   newest >>   ]

   Message 32,491 of 33,346   
   Johannes Schaub to All   
   Re: local function as default value   
   22 Jul 12 04:01:06   
   
   From: schaub.johannes@googlemail.com   
      
   Am 20.07.2012 20:44, schrieb Ivan Godard:   
   > The following seems reasonable:   
   >      struct S {   
   >          int  defVal() { return 0; }   
   >          void p(int i, int j = defVal()) {}   
   >      };   
   > but gets:   
   > error: a nonstatic member reference must be relative to a   
   >             specific object   
   >             void p(int i, int j = defVal()) {}   
   > and similar on other compilers. This seems odd to me: if "p" is to be   
   > called there must be an "S" value to be "this" at the call site, which   
   > could be used as "this" for "defVal" too. Presumably the same would   
   > apply to a local data member used as a default as well.   
   >   
      
   Sounds good to me, but I may be missing some problem this would cause.   
   Note that default arguments are late-parsed (their state of "S" is the   
   one that S has at the closing "};"), so it knows whether "p" is a const   
   or non-const member function when parsing the default argument and can   
   hence correctly overload-resolve the function name.   
      
   What would be left is making "this" visible during the declaration of   
   parameters or, which would also work here, during the parsing of default   
   arguments. But I cannot see any problem here either.   
      
      
   --   
         [ See http://www.gotw.ca/resources/clcm.htm for info about ]   
         [ comp.lang.c++.moderated.    First time posters: Do this! ]   
      
   --- SoupGate-Win32 v1.05   
    * Origin: you cannot sedate... all the things you hate (1:229/2)   

[   << oldest   |   < older   |   list   |   newer >   |   newest >>   ]


(c) 1994,  bbs@darkrealms.ca