K
kuangye
Hi, all. I encountered a compiler error. But I don't know why??
#include <vector>
#include <iostream>
using namespace std;
template<typename Container>
auto findFirst(Container&& c, typename Container::value_type low,
typename Container::value_type high)->decltype(c.iterator){
//....
//try it
return c.begin();
}
int main(){
vector<int> vi={1,2,3,4};
auto it=findFirst(vi, 2, 4);
return 0;
}
//using gcc 4.6 here
~/shared/learn_code $ g++ -std=c++0x test_erro1.cpp
test_erro1.cpp: In function ‘int main()’:
test_erro1.cpp:18:29: error: no matching function for call to
‘findFirst(std::vector<int>&, int, int)’
test_erro1.cpp:18:29: note: candidate is:
test_erro1.cpp:18:29: error: unable to deduce ‘auto’ from ‘<expression
error>’
#include <vector>
#include <iostream>
using namespace std;
template<typename Container>
auto findFirst(Container&& c, typename Container::value_type low,
typename Container::value_type high)->decltype(c.iterator){
//....
//try it
return c.begin();
}
int main(){
vector<int> vi={1,2,3,4};
auto it=findFirst(vi, 2, 4);
return 0;
}
//using gcc 4.6 here
~/shared/learn_code $ g++ -std=c++0x test_erro1.cpp
test_erro1.cpp: In function ‘int main()’:
test_erro1.cpp:18:29: error: no matching function for call to
‘findFirst(std::vector<int>&, int, int)’
test_erro1.cpp:18:29: note: candidate is:
typename Container::value_type)test_erro1.cpp:7:124: note: template said:iterator) findFirst(Container&&, typename Container::value_type,
test_erro1.cpp:18:29: error: unable to deduce ‘auto’ from ‘<expression
error>’