I have a member function of a template class declared as such:
template <class T>
int Data<T>::getPosition(vector<T> stuff, T newStuff, bool ascending)
I call this somewhere with the line
frequencies.insert(frequencies.begin() + getPosition(frequencies, current, ascending),
frequencies[i]);
The variables for that line are declared as:
vector<T> temp;
vector<int> frequencies;
int current = frequency.find(words[i])->second;
However, the call to getPosition
gives this error:
Data.h|158|error: no matching function for call to 'primitives::Data<double>::getPosition(std::vector<int, std::allocator<int> >&, int&, bool&)'|
Data.h|165|note: candidates are: int primitives::Data<T>::getPosition(std::vector<T, std::allocator<_CharT> >, T, bool) [with T = double]|
What am I doing wrong here?
getPosition
takes three arguments of type vector<T>
, T
and bool
. The templated type T
in this case is double
(as is shown in the error message), and yet you are trying to pass vector<int>
and int
as the first and second argument, respectively.
Perhaps the parameters for getPosition
should not be templated? Depends on what you are trying to achieve - you do have hard-coded int-vectors there, after all.
您的函数原型在Data<t>
上进行了模板化,看起来您正在对类型为Data<double>
的对象执行此调用,并在可能需要std::vector<double>
传递了std::vector<int>
和int
std::vector<double>
和一个double
对应于Data
对象的初始模板化类型。
vector<T> temp;
T难道不应该是int,double或bool之类的类型吗?
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.