我对模板有一个非常奇怪的问题。得到一个错误error: ‘traits’ is not a template
。我无法在示例测试项目中重现该问题。但它发生在我的项目上(比我在这里发布的要大)。
无论如何,以下是我拥有的文件和用法。任何人都知道这个错误何时发生?
我有以下内容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 {
/* ... */
}
}
}