I am having a very weird issue with templates. Getting an error error: ‘traits’ is not a template. I couldn’t reproduce the issue on a sample test project. But it happens on my project (which is bigger than I can post here).
Anyway, following are the files and usages I have. Anyone have any idea about when this error occurs?
I have the following in 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;
};
}
This is used in another header file.
namespace silc {
template<typename T>
class node {
public:
typedef typename traits<T>::const_reference const_reference;
const_reference value() const {
/* ... */
}
}
}
Syntax for template specialization is… not pleasant.
I believe your error can be fixed by replacing
struct traits<U>bystruct traits(but leavestruct traits<U*>as-is!).But look on the bright side! At least you aren’t doing partial specialization over function types: