From: musiphil@bawi.org   
      
   On 2013-03-12 16:47, Daniel Krügler wrote:   
   > Am 12.03.2013 22:33, schrieb DeMarcus:   
   >>   
   >> template   
   >> A& A::getMe( A& arg ) { ... }   
   [...]   
   >>   
   >> My question is; why do I get a compilation error for the return   
   >> type but not for the argument 'arg' that is still just an A& ?   
   >   
   > I think the reason is that in your out-of-class definition, the   
   > injected class name has not been inserted at that point (Take this   
   > with a grain of salt).   
      
   Right. More intuitively, consider this example:   
      
    struct A   
    {   
    typedef A* iterator;   
    iterator foo(iterator);   
    };   
      
    iterator A::foo(iterator) { ... } // error   
    A::iterator A::foo(iterator) { ... } // OK   
      
   You're not in the scope of A until after "A::foo", so you need the   
   prefix "A::" for the preceding return type.   
      
   > A different way of fixing your problem would be to take advantage of   
   > the "trailing-return-type" syntax, such as:   
   >   
   > template   
   > auto A::getMe( A& arg )-> A&   
   > {   
   > return *this;   
   > }   
   >   
   > Now, the return type "A&" is *after* the start of the scope and thus   
   > should be accepted as well.   
      
   This applies to my example as well:   
      
    auto A::foo(iterator) -> iterator { ... } // OK   
      
   --   
   Seungbeom Kim   
      
      
    [ 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)   
|