コンパイラエラーエラーで失敗した場合にテンプレート化:テンプレート引数の数が間違っています(2、3である必要があります)

ウドクライン

次のコードをgccでコンパイルすると

namespace TMP {
    // template to choose type depending on boolean condition
    template <bool condition, typename x, typename y> struct if_t                               { typedef y type; };
    template <                typename x, typename y> struct if_t<true, typename x, typename y> { typedef x type; };

}

TMP::if_t<false, uint8_t, uint16_t>::type test;

エラーメッセージが表示されます

error: wrong number of template arguments (2, should be 3)

2番目のテンプレートを削除すると、正常にコンパイルされます。しかし、私のコードは本のウィキブックスの例とほとんど同じだと思いました私の間違いは何ですか?

ユフェン

実際には、冗長なtypenameを削除するだけです。gcc4.9.2でコンパイルされています。

namespace TMP {
    // template to choose type depending on boolean condition
    template <bool condition, typename x, typename y>
    struct if_t
    {
        typedef y type;
    };
    template <typename x, typename y>
    struct if_t < true, x, y >
    {
        typedef x type;
    };

}

この記事はインターネットから収集されたものであり、転載の際にはソースを示してください。

侵害の場合は、連絡してください[email protected]

編集
0

コメントを追加

0

関連記事

Related 関連記事

ホットタグ

アーカイブ