[英]Can we specialize a enum (type) member of a class template?
Cppreference聲稱,除其他外,你可以專攻一個
- 成員枚舉類模板
由於沒有提供示例,我試圖猜測如何做到這一點。
我最終得到了以下內容:
template <typename T> struct A
{
enum E : int;
};
template <> enum A<int>::E : int {a,b,c};
Clang(8.0.0 with -std=c++17 -pedantic-errors
)編譯它。
GCC(9.1 with -std=c++17 -pedantic-errors
)拒絕代碼
error: template specialization of 'enum A<int>::E' not allowed by ISO C++ [-Wpedantic]
MSVC(帶有/std:c++latest
v19.20也拒絕了代碼
error C3113: an 'enum' cannot be a template
我是否正確地專注於枚舉? 如果沒有,現在我這樣做?
標准中有一些例子([temp.expl.spec] / 6)表明你所擁有的是正確的。 那個是:
template<> enum A<int>::E : int { eint }; // OK
好像是一個gcc bug。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.