次のコードを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]
コメントを追加