현재 C++ 컴파일러 (최신 GCC, 그 소리는) 아래의 예에서 typename
키워드 필요합니다 typename
는 GCC (4.9, 5.0)를 생략 오류보고있다함수 템플릿 내에서 선언 된 경우 로컬 클래스에 종속됩니까?
template<class T>
struct A
{
};
template<class T>
void f(T)
{
struct C
{
};
typedef typename A<C>::Type Type; // typename required
}
경우
need 'typename' before 'A<f(T)::C>::Type' because 'A<f(T)::C>' is a dependent scope
이 예를 그렇지 않으면 C++ 11 표준을 읽었을 때 잘 형성됩니다.
이 문제는 다음과 같은 표현에 의해 덮여있는 것 같다 : 그러나
[temp.dep.type]/8
A type is dependent if it is
a template parameter,
a member of an unknown specialization,
a nested class or enumeration that is a member of the current instantiation,
a cv-qualified type where the cv-unqualified type is dependent,
a compound type constructed from any dependent type,
an array type constructed from any dependent type or whose size is specified by a constant expression that is value-dependent,
a simple-template-id in which either the template name is a template parameter or any of the template arguments is a dependent type or an expression that is type-dependent or value-dependent, or
denoted by decltype(expression), where expression is type-dependent.
클래스가 C
로컬 클래스보다는 중첩 클래스이다 class.local] 방법. 그렇다면 A<C>
을 부양 가족으로 취급해야하는 이유는 무엇입니까?
EDIT 보너스 포인트
, 다음과 같은 예 C
에 부재 ENUM을 추가하여 변경되는 경우 :
template<typename T>
struct A
{
typedef T Type;
};
template<class T>
void f(T)
{
struct C
{
enum { value = T::value };
};
typedef typename A<C>::Type Type; // typename required
}
가 A<C>
지금 따라 취급되어야 하는가?
이것은 DR 1484와 관련이있는 것 같습니다. http://www.open-std.org/jtc1/sc22/wg21/docs/cwg_defects.html – willj
그들은 DR 페이지에서 앵커를 사용하므로 링크를 제공 할 수 있습니다 http://www.open-std.org/jtc1/sc22/wg21/docs/cwg_defects.html#1484 – dyp
'typename'이 필요하다고 생각합니다. 다음과 같은 별난 예제를 고려해보십시오. http://coliru.stacked-crooked.com/a/a03aebd672bfa7c7 'C'의 정의 *는 이름이 아니더라도 템플릿 매개 변수에 따라 달라질 수 있습니다. – dyp