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,632 of 33,346   
   =?ISO-8859-15?Q?Daniel_Kr=FCgler?= to All   
   Re: template syntax problem   
   03 Nov 12 23:54:08   
   
   From: daniel.kruegler@googlemail.com   
      
   Am 04.11.2012 00:21, schrieb Klaus:   
   >   
   > Hi, I can't get the following sample code to run:   
   >   
   >     1 #include    
   >     2   
   >     3 using namespace std;   
   >     4   
   >     5   
   >     6 class MyClass   
   >     7 {   
   >     8    public:   
   >     9       template   
   >    10          static T AnyFunc();   
   >    11   
   >    12 };   
   >    13   
   >    14 template <> int MyClass::AnyFunc () { return 1; }   
   >    15 template <> double MyClass::AnyFunc() { return 2.2222; }   
   >    16   
   >    17   
   >    18 template    
   >    19 class Y   
   >    20 {   
   >    21    public:   
   >    22       T Caller() { return X::AnyFunc(); }   
      
   The root of the problem is that you are within a template context and   
   here the expression   
      
   X::AnyFunc()   
      
   (where X is dependent) is required to be interpreted less operator (<)   
   applied to X::AnyFunc unless you tell the compiler that AnyFunc is   
   actually a template (this is not unambiguously clear here) by   
   introducing a template prefix to   
      
   X::template AnyFunc()   
      
   So the complete function definition should look so:   
      
   T Caller() { return X::template AnyFunc(); }   
      
   HTH & Greetings from Bremen,   
      
   Daniel Krügler   
      
      
   --   
         [ 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