C++ template won't accept iterators

萝らか妹 提交于 2019-11-28 02:20:33

The compiler has no way to deduce T from your function call. Think about what happens when std::vector<T>::iterator is T*:

int *b = ...;
int *e = ...;
QSort(b, e);

In general, if you write typename Something<TemplateParameter>::anotherThing, then the TemplateParemter cannot be deduced in the call. It must be explicitly provided

QSort<int>(b, e);

I recommend to just use T as the parameter type. That will allow you to not only accept vector iterators, but also T*, or std::deque<T>::iterator and any other random access iterators.

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!