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)   
|