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 33,266 of 33,346   
   alapaa to Niklas   
   Re: Problem with templates   
   13 Dec 13 06:39:20   
   
   From: erik.alapaa@bredband.net   
      
   On Monday, December 9, 2013 10:17:36 PM UTC+1, Niklas wrote:   
   > I have a strange problem with templates in c++. I need to access a   
   > singleton with template methods inside another templated class. The   
   > problem is isolated in the following piece of code, which doesnt   
   > compile. For example, in gcc 4.7.3 you will get   
   > >   
   >   test.cpp:15:23: error: expected primary-expression before 'int'   
   >   
      
   FWIW, the code works in clang, (Ubuntu clang version 3.0-6ubuntu3). I   
   only added a cout print to check that the output was sane and the   
   program works:   
      
   #include    
      
   class A {   
   public:   
   template   
   T get() { return 0; }   
   };   
      
   static A a;   
      
   template   
   class B {   
   public:   
      
   static A& bar() { return a; }   
   static int foo() {   
      int x = bar().get(); // This doesnt compile   
      
           // Replace with int x = a.get(); will do the trick.   
      
                return x;   
   }   
   };   
      
   int   
   main(int argc, char * argv[]) {   
      std::cout << B::foo() << '\n';   
      return 0;   
   }   
      
      
   Regards,   
      
   /Erik Alapää   
      
      
   --   
         [ 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