So i have a templated function:
template<typename T>
int func(const T& input){
//do stuff
}
And I'd like to specialise it with a templated class(like std::vector) So like this:
template<typename T>
int func(const std::vector<T>& input){
//do specialised stuff
}
But I don't know how exactly you do it. Thanks!
simply go on
#include <vector>
#include <iostream>
using namespace std;
template<typename T>
int func(const vector<T>& a){
for(auto i: a) //do specialised stuff
cout<< (i<<1) <<"\n";
return 0;
}
int main() {
vector<int> a={9,8,7};
func(a);
}
18
16
14
multiple each array a by 2 (shift left once, << 1)
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.