Suppose I have two classes Foo1<T> and Foo2<T>.
I then want to create a function bar that takes a reference to a std::vector<Foo1<T>> or to a std::vector<Foo2<T>> but always returns a std::vector<Foo1<T>>:
template<class T, class Y> std::vector<Foo1<T>> bar(std::vector<Y<T>>&)
Sadly but the compiler doesn't like the <Y<T>> bit. One way round this is to provide two overloads but is there a way I can arrange the above so it's correct?
Aucun commentaire:
Enregistrer un commentaire