刚刚自学C++在vs里面写的程序,biggies的定义被当成了重载,具体如下

biggies()函数在主程序同一个文件内定义的话会被当成重载,而elimDups()函数则不会,难道是因为elimDups()函数没有在主程序中调用吗?同时如果将biggies()函数放到另一个文件中定义就不会出现上面的问题。


#include <iostream>
#include <vector>
#include <string>
#include <algorithm>
using namespace std;
void elimDups(vector<string>& words);
void biggies(vector <string>& words, vector<string>::size_type sz);

int main(void) 
{
    vector<string> words = { "the","quick","red","fox","jumps","over","the","slow","red","turtle" };
    auto sz = 4;
    biggies(words,sz);

    return 0;
}

void biggies(vector<string> words, vector<string>::size_type sz)
{
    elimDups(words);
    stable_sort(words.begin(), words.end(), [](const string& a, const string& b) {return a.size() < b.size(); });
    auto wc = find_if(words.begin(), words.end(), [sz](const string &a) {return a.size() >= sz; });
    for_each(wc, words.end(), [](const string& s) {cout << s << " "; });
    cout << endl;
}

void elimDups(vector<string>& words) 
{
    sort(words.begin(), words.end());
    auto unique_end = unique(words.begin(), words.end());
    words.erase(unique_end, words.end());
}

img