简体   繁体   中英

C++ templates and “no matching function to call”

I'm getting a strange error. 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 like this:

 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);

The U* and R* are aliases for the unsigned integer and floating point types, respectively. What's weird is that all the integer ones work perfectly, while the floating point ones fail with a somewhat enigmatic error:

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

Any thoughts?

you can not use floating point numbers at template value parameters.

Template value parameters must be integral types, ICE to be exact: http://publib.boulder.ibm.com/infocenter/comphelp/v8v101/index.jsp?topic=/com.ibm.xlcpp8a.doc/language/ref/template_non-type_arguments.htm

As aaa pointed out, you can't use floating point numbers as template value parameters. But in this instance you don't need to. Get rid of the second parameter entirely, and then in the definition of ConvertCbYCrYToRGB instead of using 'max' use std::numeric_limits<DATA>::max() . Documentation on numeric_limits is here: http://www.cplusplus.com/reference/std/limits/numeric_limits/

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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