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,920 of 33,346    |
|    DeMarcus to All    |
|    Why does my template need a type?    |
|    12 Mar 13 14:33:42    |
   
   From: use_my_alias_here_at_hotmail_com@tellus.orb.dotsrc.org   
      
   Hi,   
      
   Usually I want to separate the declaration from the definition also   
   for templates, but I bumped into an interesting error when doing that   
   recently. Consider this separation.   
      
   template   
   class A   
   {   
   public:   
    A& getMe( A& arg ); // Separated implementation below.   
   };   
      
   template   
   A& A::getMe( A& arg )   
   {   
    return *this;   
   }   
      
   int main()   
   {   
    A a;   
    A b;   
    a.getMe( b );   
    return 0;   
   }   
      
   This code gives me on gcc 4.7.2.   
   error: invalid use of template-name ‘A’ without an argument list   
      
   But if I change the return type to look like the following, it   
   compiles.   
      
   template   
   A& A::getMe( A& arg )   
   {   
    return *this;   
   }   
      
   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& ?   
      
      
   Thanks,   
   Daniel   
      
      
   --   
    [ 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