如果我用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)
如果删除第二个模板,它将成功编译。但是我认为我的代码与Wikibook示例中的代码几乎相同。我怎么了
实际上,只需删除多余的typename。用gcc 4.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] 删除。
我来说两句