简体   繁体   English

C ++错误:没有匹配的函数可用于调用函数模板

[英]C++ error: no matching function for call to function template

I have a function template that extracts data from an image and copies it to a smaller array (which I call a Patch ) the template function is called copyPatch . 我有一个函数模板,该模板从图像中提取数据并将其复制到一个较小的数组(我称之为Patch ),该模板函数称为copyPatch It is defined as: 它定义为:

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)

Note: the Transformation parameter allows me to pass in a class that performs some transformation on the data. 注意: Transformation参数允许我传入一个对数据执行一些转换的类。 I call the template function as follows, 我按以下方式调用模板函数,

copyPatch<float, uint8_t, StraightCopy>(m_patch_data, m_data.t8u,
                                        ul_pix, ul_line)

where m_patch_data is of type Patch<float> and m_data.t8u is a member of a union defined as follows: 其中, 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;

When I compile this I get the following error (that I've doctored a bit): 当我对此进行编译时,出现以下错误(我已经进行了一些修改):

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:

To me, I don't see why the function didn't match. 对我来说,我不明白为什么功能不匹配。 The only possible reason I can see is that for the 2nd parameter it wants a pointer (which is what I thought I was passing), but the calling code seems to be passing a reference to a pointer. 我可以看到的唯一可能原因是,对于第二个参数,它想要一个指针(这是我以为我要传递的指针),但是调用代码似乎正在传递对指针的引用。

Compiler is g++ 4.8.1. 编译器为g ++ 4.8.1。

As pointed out in the comments the problem possibly with my Transformation (StraightCopy) which is defined as follows: 正如评论中指出的那样,我的Transformation(StraightCopy)可能存在问题,其定义如下:

template<class Dest, class Src>
class StraightCopy {
public:
    Dest operator()(Src s) { return static_cast<Dest>(s); } 
};

I missed passing the parameters to my StraightCopy class. 我错过了将参数传递给StraightCopy类的操作。

Thanks to PlasmaHH for pointing me in the right direction. 感谢PlasmaHH为我指出正确的方向。 My transformation type (StraightCopy) needed parameters. 我的转换类型(StraightCopy)需要参数。 So my call looks like: 所以我的电话看起来像:

copyPatch<float, uint8_t, StraightCopy< float, uint8_t > >( m_patch_data, m_data.t8u, ul_pix, ul_line);

Isn't that beautiful :o) 那不是很漂亮吗:o)

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM