VS中C2091,C2207错误

for (multimap<double, int, greater<int>()>::iterator it = groupScore.begin(); it != groupScore.end(); it++)
{
	cout << "编号" << it->second << "姓名" << this->m_Speaker[it->second].m_Name << "成绩" << this->m_Speaker[it->second].m_Score[this->m_Index - 1] << endl;
}

代码的功能是遍历multimap迭代器,输出迭代器中的信息

但是我由于STL容器基础知识不过关,把greater<int>()写成了一个函数,这种方法是不对的

正确的写法如下:

for (multimap<double, int, greater<int>>::iterator it = groupScore.begin(); it != groupScore.end(); it++)
{
	cout << "编号" << it->second << "姓名" << this->m_Speaker[it->second].m_Name << "成绩" << this->m_Speaker[it->second].m_Score[this->m_Index - 1] << endl;
}

 有一个问题需要指出的就是:

在以下代码中,greater<double>()就需要带上括号显示,因为sort算法的第三个参数是谓词。

sort(d.begin(), d.end(),greater<double>());

  

posted @ 2021-06-10 17:35  进寸欢喜  阅读(110)  评论(0编辑  收藏  举报