C 错误:呼叫函数模板没有匹配功能
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
是定义如下的联合的成员:
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。
正如评论中指出的那样,我的转换(直接拷贝)的问题定义如下:
template<class Dest, class Src>
class StraightCopy {
public:
Dest operator()(Src s) { return static_cast<Dest>(s); }
};
我错过了将参数传递给我的直型类。
感谢plasmahh将我指向正确的方向。我的转换类型(直接拷贝)需要参数。所以我的电话看起来像:
copyPatch<float, uint8_t, StraightCopy< float, uint8_t > >( m_patch_data, m_data.t8u, ul_pix, ul_line);
不是那么美丽:o)
相关文章:
- 当函数模板参数是具有默认参数的类模板时,函数模板参数的推导如何执行
- 将重载的成员函数传递给函数模板
- C++17中函数模板中的静态数组初始化(MSVC 2019)
- 为什么 gcc 和 clang 为函数模板的实例化生成不同的符号名称?
- 具有常量引用参数的函数模板专用化
- std::span<const T> 作为函数模板中的参数
- 如何编写一个完美的缩写函数模板?
- 仅在函数模板中为那些定义了函数的类型执行函数
- 如何在C++中伪造虚拟可变参数函数模板?
- 以下代码中的函数模板有什么问题?
- 在 C++20 中是否不再允许在 std 中对程序定义类型的函数模板进行专用化?
- 将显式实例化的函数模板与转换匹配
- 使用定义函数模板别名
- 函数模板返回类型
- C 函数调用包装器包含类成员功能作为模板参数
- 可以在功能参数列表中多次使用函数模板的模板参数名称
- 具有自动功能的模板函数的重载分辨率
- 获取模板功能函数返回类型的功能类型
- C 错误:呼叫函数模板没有匹配功能
- 使用成员函数模板实现接口的功能