簡體   English   中英

具有地圖分配器問題的C ++模板

[英]C++ template with map allocator problem

我定義了一個模板函數,該函數從CSV文件加載地圖:

template <class T>
bool loadCSV (QString filename, map<T,int> &mapping){
    // function here
}

然后,我嘗試使用它:

map<int, int> bw;
loadCSV<int>((const QString)"mycsv.csv",&bw);

但是得到htis編譯時錯誤:

error: no matching function for call to 
‘loadCSV(const QString, std::map<int, int, std::less<int>, std::allocator<std::pair<const int, int> > >*)’

看來我的函數調用引入了一些隱式參數,但是我不理解該錯誤以及如何解決它。 有任何想法嗎?

放下“&”號,您就不想傳遞指向地圖的指針(請注意錯誤消息末尾的星號)。 另外,您不必顯式轉換字符串文字。 而且,編譯器應該能夠自動推斷出模板參數。

loadCSV("mycsv.csv", bw);

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM