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,464 of 33,346   
   Seungbeom Kim to DeMarcus   
   Re: Are enums allowed as template parame   
   07 Jul 12 16:56:56   
   
   From: musiphil@bawi.org   
      
   On 2012-07-07 12:51, DeMarcus wrote:   
   >   
   > I've moved out Vals as you said and it worked, but then I changed   
   > Initialized one;   
   > to   
   > Initialized one;   
   >   
   > and I get   
   > In function ‘int main(int, char**)’:   
   > error: template argument 2 is invalid   
   > error: invalid type in declaration before ‘;’ token   
   >   
   > using g++ 4.7.1   
   >   
   > (it works if I add -std=c++0x)   
      
   That's because the plain enum, formally called "unscoped enumeration",   
   doesn't introduce a new scope, and its enumerator ONE lives in the scope   
   that contains the enum-name Vals.   
      
   C++11 introduced "scoped enumeration", which is declared with "enum class"   
   or "enum struct" and which introduces its own scope. It also seems to have   
   relaxed the rule for unscoped enumerations so that their enumerators can   
   also be referred to as within their own scopes.   
      
   [Example from 7.2/10]   
      
   enum direction { left=’l’, right=’r’ };   
      
   void g() {   
    direction d;                  // OK   
    d = left;                     // OK   
    d = direction::right;         // OK   
   }   
      
   enum class altitude { high=’h’, low=’l’ };   
      
   void h() {   
    altitude a;                   // OK   
    a = high;                     // error: high not in scope   
    a = altitude::low;            // 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)   

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


(c) 1994,  bbs@darkrealms.ca