B
blaz.bratanic
#include <iostream>
#include <vector>
#include <list>
template <typename T>
void foo(T a) {
std::cout << "General" << std::endl;
}
template <typename T>
void foo(std::vector<T> a) {
std::cout << "Vector" << std::endl;
}
int main() {
std::vector<int> v = {1,2,3};
foo(v); // vector
std::list<int> l = {1,2,3};
foo(l); // general
}
Could someone explain does the call to foo not result in an ambiguous call?
Probably the question is, why the compiler prefers
foo<int> over foo<std::vector<int>>?
thanks
#include <vector>
#include <list>
template <typename T>
void foo(T a) {
std::cout << "General" << std::endl;
}
template <typename T>
void foo(std::vector<T> a) {
std::cout << "Vector" << std::endl;
}
int main() {
std::vector<int> v = {1,2,3};
foo(v); // vector
std::list<int> l = {1,2,3};
foo(l); // general
}
Could someone explain does the call to foo not result in an ambiguous call?
Probably the question is, why the compiler prefers
foo<int> over foo<std::vector<int>>?
thanks