gpt4 book ai didi

c++ - 通过迭代器修改 std::set 元素:为什么我的代码没有编译?

转载 作者:行者123 更新时间:2023-11-30 00:39:46 26 4
gpt4 key购买 nike

已更新

这是给我带来麻烦的方法:

void A::normalizeUrls()
{
for (set<CUrl>::iterator it = _references.begin(); it != _references.end(); ++it)
{
if (it->isValid())
{
it->normalize().makeFull(_baseUrl);
}
}
}

这里是 CUrl::normalize 和 CUrl::makeFull

CUrl& makeFull (CUrl&)
{
return *this;
}
CUrl& CUrl::normalize()
{
return *this;
}

错误是:CUrl::normalize':无法将 'this' 指针从 'const CUrl' 转换为 'CUrl &'

'.makeFull' 的左边必须有类/结构/union

为什么会这样,我错过了什么?

提前致谢!

最佳答案

auto 将删除引用。我不知道 auto& 是否有效,但如果无效,您必须明确指定 CUrl&

关于c++ - 通过迭代器修改 std::set 元素:为什么我的代码没有编译?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/7986744/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com