Newsgroup: comp.lang.c++
Subject: Function overloading question
From: blaz.bratanic@...
Date: Thu, 5 Dec 2013 02:40:01 -0800 (PST)
#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
Subject: Function overloading question
From: blaz.bratanic@...
Date: Thu, 5 Dec 2013 02:40:01 -0800 (PST)
#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
via Usenet Forums - Usenet Search,Free Usenet - comp.lang.c++ http://www.pocketbinaries.com/usenet-forums/showthread.php?143578-Function-overloading-question&goto=newpost
View all the progranning help forums at:
http://www.pocketbinaries.com/usenet-forums/forumdisplay.php?128-Coding-forums
No comments:
Post a Comment