且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

为什么我不能将const map结构传递给c ++中的函数?

更新时间:2022-01-13 00:18:04

我相信这是因为 [] 在map中不是 const ,因为它创建具有默认值的新对,如果您寻址到不存在的对。尝试

I believe that it is because [] in map isn't const, as it creates new pair with default value, if you address to nonexisting one. Try

void pas(const map <string, float> &mm)
{
    cout<<mm.find("a")->second;
    cout<<mm.find("b")->second;
}