好吧,所以我只是学习模板。不管怎么说,我可能(最绝)做错了,但这里的问题:C++模板函数特化 - 模板参数数量错误?
我的第一个模板函数声明如下:
template<typename T>
std::ostream& printFormatted(T const& container, std::ostream& os = std::cout) {
//...
}
然后我应该实现一个专门的案例地图,所以这就是我试图做的:
template<>
std::ostream& printFormatted<std::map<typename key, typename value>>(std::map<typename key, typename value> const& container, std::ostream& os = std::cout) {
//...
}
我可能会做出与我的键/值的变量,不知道,但无论一个错误,试图编译我得到的错误消息时:
error: wrong number of template arguments (1, should be 4)
error: provided for ‘template<class _Key, class _Tp, class _Compare, class _Allocator> class std::__debug::map’
显然有一些我不明白的模板或地图?有人请帮忙?
是'key'和'value'实际类型的代码或者你打算在他们的占位符? –