好吧,所以我只是學習模板。不管怎麼說,我可能(最絕)做錯了,但這裏的問題: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'實際類型的代碼或者你打算在他們的佔位符? –