2

テンプレートに関して非常に奇妙な問題が発生しています。エラーが発生します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 {
            /* ... */
        }
    }
}
4

1 に答える 1

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*)> { ... };
于 2010-02-21T06:06:36.490 に答える