[英]C++ error: no matching function for call to function template
我有一個函數模板,該模板從圖像中提取數據並將其復制到一個較小的數組(我稱之為Patch
),該模板函數稱為copyPatch
。 它定義為:
template <class DestType, class SrcType, class Transformation>
bool copyPatch(Patch<DestType> &patch,
ImageData<SrcType>* src_data,
size_t src_ul_pix,
size_t src_ul_line)
注意: Transformation
參數允許我傳入一個對數據執行一些轉換的類。 我按以下方式調用模板函數,
copyPatch<float, uint8_t, StraightCopy>(m_patch_data, m_data.t8u,
ul_pix, ul_line)
其中, m_patch_data
的類型為Patch<float>
, m_data.t8u
是定義如下的並m_data.t8u
的成員:
union {
ImageData<uint8_t>* t8u;
ImageData<uint16_t>* t16u;
ImageData<int16_t>* t16s;
ImageData<uint32_t>* t32u;
ImageData<int32_t>* t32s;
// A bunch more of these
void* tvoid;
} m_data;
當我對此進行編譯時,出現以下錯誤(我已經進行了一些修改):
error: no matching function for call to:
copyPatch(Patch<float>&, ImageData<unsigned char>*&, size_t&, size_t&)’
copyPatch<float, uint8_t, StraightCopy>( m_patch_data, m_data.t8u, ul_pix, ul_line);
^
note: candidate is:
template<class DestType, class SrcType, class Transformation>
bool copyPatch(Patch<T>&, ImageData<SrcType>*, size_t, size_t)
template argument deduction/substitution failed:
對我來說,我不明白為什么功能不匹配。 我可以看到的唯一可能原因是,對於第二個參數,它想要一個指針(這是我以為我要傳遞的指針),但是調用代碼似乎正在傳遞對指針的引用。
編譯器為g ++ 4.8.1。
正如評論中指出的那樣,我的Transformation(StraightCopy)可能存在問題,其定義如下:
template<class Dest, class Src>
class StraightCopy {
public:
Dest operator()(Src s) { return static_cast<Dest>(s); }
};
我錯過了將參數傳遞給StraightCopy類的操作。
感謝PlasmaHH為我指出正確的方向。 我的轉換類型(StraightCopy)需要參數。 所以我的電話看起來像:
copyPatch<float, uint8_t, StraightCopy< float, uint8_t > >( m_patch_data, m_data.t8u, ul_pix, ul_line);
那不是很漂亮嗎:o)
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.