2010-02-21 33 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

谢谢。那是我犯过的一个愚蠢的错误。再次感谢您指出。 – 2010-02-21 06:12:11