[英]couldn't deduce template parameter ‘U
I have a following function I want to use:我想使用以下 function:
template <typename T>
template <typename U>
TypedData<U>* convert(T min, T max) const;
Here's how I used it in the code:这是我在代码中使用它的方式:
const TypedData<unsigned short>* B = A->convert((float)0,(float)65535);
where A is the following type:其中 A 是以下类型:
const TypedData<float>*
The complier gives me the following error and notes:编译器给了我以下错误和注释:
error: no matching function for call to ‘TypedData<float>::convert(float, float) const’
note: candidate: template<class U> TypedData<U>* TypedData<T>::convert(T, T) const [with U = U; T = float]
TypedData<U>* convert(T min, T max) const;
note: template argument deduction/substitution failed:
note: couldn't deduce template parameter ‘U
I want to ask if I am using this template function correctly?我想问一下我是否正确使用了这个模板function? and what is the reason that it gives me the error.
它给我错误的原因是什么。 Thanks.
谢谢。
You need to provide the U
template parameter to convert
as well:您还需要提供要
convert
的U
模板参数:
const TypedData<unsigned short>* B =
A->convert<unsigned short>((float)0,(float)65535);
Note that this means you can avoid specifying the template parameter on the left hand side:请注意,这意味着您可以避免在左侧指定模板参数:
const auto* B =
A->convert<unsigned short>((float)0,(float)65535);
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.