metestudio 2021-11-04 18:37 采纳率: 100%
浏览 13
已结题

刚刚自学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());
}
  • 写回答

1条回答 默认 最新

  • 关注

    img

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

问题事件

  • 系统已结题 11月14日
  • 已采纳回答 11月6日
  • 创建了问题 11月4日

悬赏问题

  • ¥15 路易威登官网 里边的参数逆向
  • ¥15 Arduino无法同时连接多个hx711模块,如何解决?
  • ¥50 需求一个up主付费课程
  • ¥20 模型在y分布之外的数据上预测能力不好如何解决
  • ¥15 processing提取音乐节奏
  • ¥15 gg加速器加速游戏时,提示不是x86架构
  • ¥15 python按要求编写程序
  • ¥15 Python输入字符串转化为列表排序具体见图,严格按照输入
  • ¥20 XP系统在重新启动后进不去桌面,一直黑屏。
  • ¥15 opencv图像处理,需要四个处理结果图