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 微信公众平台自制会员卡可以通过收款码收款码收款进行自动积分吗
  • ¥15 随身WiFi网络灯亮但是没有网络,如何解决?
  • ¥15 gdf格式的脑电数据如何处理matlab
  • ¥20 重新写的代码替换了之后运行hbuliderx就这样了
  • ¥100 监控抖音用户作品更新可以微信公众号提醒
  • ¥15 UE5 如何可以不渲染HDRIBackdrop背景
  • ¥70 2048小游戏毕设项目
  • ¥20 mysql架构,按照姓名分表
  • ¥15 MATLAB实现区间[a,b]上的Gauss-Legendre积分