2010-02-21 7 views
2

템플릿과 관련하여 매우 이상한 문제가 있습니다. 오류가 발생했습니다 error: ‘traits’ is not a template. 샘플 테스트 프로젝트에서 문제를 재현 할 수 없었습니다. 그러나 그것은 내 프로젝트에서 발생합니다 (이 글은 제가 게시 할 수있는 것보다 큽니다).오류 : '특성'이 템플릿이 아닙니다. - C++

어쨌든 다음 파일과 사용법은 다음과 같습니다. 누구든지이 오류가 발생할 때 어떤 생각을 가지고 있습니까?

다음은 traits.hpp입니다.

namespace silc 
{ 
    template<class U> 
    struct traits<U> 
    { 
     typedef const U& const_reference; 
    }; 

    template<class U> 
    struct traits<U*> 
    { 
     typedef const U* const_reference; 
    }; 
} 

다른 헤더 파일에서 사용됩니다.

namespace silc { 

    template<typename T> 
    class node {     
    public: 

     typedef typename traits<T>::const_reference const_reference; 

     const_reference value() const { 
      /* ... */ 
     } 
    } 
} 

답변

3

템플릿 전문화에 대한 구문이 유쾌하지 않습니다.

나는 struct traits<U>struct traits (단, struct traits<U*>은있는 그대로!)으로 대체하여 오류를 수정할 수 있다고 생각합니다.

하지만 밝은면을보세요! 적어도 함수 유형보다는 부분적 특수화를 수행하지 않습니다.

// Partial class specialization for 
// function pointers of one parameter and any return type 
template <typename T, typename RetVal> 
class del_ptr<T, RetVal (*)(T*)> { ... }; 

// Partial class specialization for 
// functions of one parameter and any return type 
template <typename T, typename RetVal> 
class del_ptr<T, RetVal(T*)> { ... }; 

// Partial class specialization for 
// references to functions of one parameter and any return type 
template <typename T, typename RetVal> 
class del_ptr<T, RetVal(&)(T*)> { ... }; 
+1

감사합니다. 그것은 내가 한 바보 같은 실수였다. 다시 지적 해 주셔서 감사합니다. –

관련 문제