C ++ templates and "Lack of a suitable function to call"

I have a strange mistake. I have a function of the following signature:

template <typename DATA, DATA max> static bool ConvertCbYCrYToRGB(const Characteristic space, const DATA *input, DATA *output, const int pixels) { 

Which is later called the following:

  case kByte: return ConvertCbYCrYToRGB<U8, 0xFF>(space, (const U8 *)input, (U8 *)output, pixels); case kWord: return ConvertCbYCrYToRGB<U16, 0xFFFF>(space, (const U16 *)input, (U16 *)output, pixels); case kInt: return ConvertCbYCrYToRGB<U32, 0xFFFFFFFF>(space, (const U32 *)input, (U32 *)output, pixels); case kFloat: return ConvertCbYCrYToRGB<R32, FLT_MAX>(space, (const R32 *)input, (R32 *)output, pixels); case kDouble: return ConvertCbYCrYToRGB<R64, DBL_MAX>(space, (const R64 *)input, (R64 *)output, pixels); 

U * and R * are aliases for unsigned and floating point integers, respectively. What is strange is that all integers work fine, while floating point fail with some cryptic error:

 DPXColorConverter.cpp:171: error: no matching function for call to 'ConvertCbYCrYToRGB(const dpx::Characteristic&, const dpx::R32*, dpx::R32*, const int&)' 

Any thoughts?

+4
source share
2 answers

As stated in aaa, you cannot use floating point numbers as template parameters. But in this case you do not need. Get rid of the second parameter entirely, and then use std::numeric_limits<DATA>::max() instead of using 'max' in the ConvertCbYCrYToRGB definition. The documentation for numeric_limits is here: http://www.cplusplus.com/reference/std/limits/numeric_limits/

+2
source

you cannot use floating point numbers in the parameters of a pattern value.

The parameters of the template parameters must be integer types, ICE, to be precise: http://publib.boulder.ibm.com/infocenter/comphelp/v8v101/index.jsp?topic=/com.ibm.xlcpp8a.doc/language/ref /template_non-type_arguments.htm

+4
source

Source: https://habr.com/ru/post/1316435/


All Articles