对于两个不同的重载函数,两个之间可以互相调用,如下代码
void testoveride(std::string s){ std::cout<<s<<std::ends; } void testoveride(std::vector<std::string> s){ testoveride(s.at(1)); } std::vector<std::string> s; s.push_back(std::string("1")); s.push_back(std::string("2")); testoveride(s);
假如对于两个重载的函数模版
template<class T> void testoveride(T s){ std::cout<<s<<std::ends; } template<class T> void testoveride(std::vector<T> s){ testoveride(s.at(1)); } std::vector<std::string> s; s.push_back(std::string("1")); s.push_back(std::string("2")); testoveride(s);
正确的输出“2”