2010-06-14 4 views
1

가능한 복제를 발행합니다
problem with template inheritanceGCC 템플릿은

이 코드는 GCC로 컴파일되지 않습니다 중 하나 Base 또는 Sub 템플릿 클래스가 아니었다면

template <typename T> 
struct Base 
{ 
public: 
int x; 
}; 

template <typename B> 
struct Middle : public B 
{ 
}; 

template <typename T> 
struct Sub : public Middle<Base<T> > 
{ 
public: 
void F() 
{ 
    x=1; // error: ‘x’ was not declared in this scope 
} 
}; 

을 , 그것은 불평하지 않을 것이다. VC가 처리합니다.

왜?

+0

[템플릿 상속 문제] 중복 (http://stackoverflow.com/questions/2982660/problem-with-template-inheritance) –

답변

4

이 (템플릿) 종속 이름임을 컴파일러에 알리기 위해 this->x = 1;을 사용하십시오. 참고 : GCC가 표준에 따라 잘하는 것은 MSVC가 좀 더 관대합니다.

관련 문제