2015-10-04 88 views
0

我使用具有與嵌套在一個類枚舉類頭一個C++ 11庫:嵌套在類中的C++ 11枚舉類的縮寫語法?

class ClassWithARatherLongName 
{ 
public: 
    enum class EnumWithARatherLongName 
    { 
     VALUE1, 
     VALUE2, 
     VALUE3 
    }; 
    (other code) 
}; 

然後我用我的代碼統計員:

void foo() 
{ 
    ... ClassWithARatherLongName::EnumWithARatherLongName::VALUE1 ... 
} 

這工作,但是乏味的。沒有縮小語法的方法嗎?

理想情況下,我想能夠寫類似:

void foo() 
{ 
    (some directive that allows to use an abbreviated syntax) 
    ... VALUE1 ... 
} 

回答

2

您可以使用typedefusing創建一個「捷徑」:

using E = ClassWithARatherLongName::EnumWithARatherLongName; 
E::VALUE1 
+0

幾乎短了我的希望。如果有辦法擺脫'E ::',那會更好。 – user1387866

0

只需添加一個typedef:

void foo() 
{ 
    typedef ClassWithARatherLongName::EnumWithARatherLongName e; 
    e::VALUE1 
} 

您可能能夠縮短名稱,使用的命名空間。