模板化失败,出现编译错误错误:模板参数数量错误(2,应该是3)
Templated if fails with compiler error error: wrong number of template arguments (2, should be 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)
如果我删除第二个模板,它将成功编译。然而,我认为我的代码几乎是相同的书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;
};
}
在yufeng的帮助下,我发现了应该怎么做:
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;
相关文章:
- 尝试使用 std::vector<std::thread时出现静态断言失败错误>
- Websocket++ 错误:收到错误handle_transport_init TLS 握手失败
- Netbeans 10:错误:链接器命令失败,退出代码为 1(使用 -v 查看调用)
- 这个失败的测试是将零添加到空指针未定义的行为、编译器错误还是其他什么?
- 构建失败错误:无法使用 qibuild 构建C++ SDK Helloworld
- q网络回复 无状态码或错误,但失败
- 创建服务失败0x6f7存根收到错误数据
- 两个线程一个使用流 Api,另一个线程创建文件失败并出现错误ERROR_SHARING_VIOLATION
- CMake 错误:链接器命令失败,退出代码为 1 和 cpp.o 文件
- clang:错误:链接器命令失败,退出代码为 1(使用 -v 查看调用) - 体系结构的未定义符号 x86_64:
- 调试模板时出现问题.专门针对 Linux GCC 7、GCC 6、GCC 5、GCC 4.9 错误构建失败:模板参数 1
- 如何修复 clang: 错误:链接器命令失败,退出代码为 1(使用 -v 查看调用)
- 错误:断言失败 (src.type() == CV_8UC1) 在阈值中
- 失败,出现错误 87:参数不正确.如何判断哪个参数不正确?
- 创建进程 API 失败,在窗口 122 上出现错误代码 10
- 加速兽握手:sslv3 警报握手失败错误
- 自定义预期失败的完整错误消息(boost::spirit::x3)
- 从 Linux OMI (omicli) 到 Windows WMI 的连接失败,并出现与 DMTF 相关的错误
- libcurl错误失败的写作已接收到磁盘/应用程序的数据
- std::timed_mutex::try_lock*错误失败