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

标签 c++ compilation

已更新

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

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/

相关文章:

编译时在代码中替换了 Java 静态最终值?

macros - 如果未设置某些宏,则阻止 systemverilog 编译

c++ - 如果我在 Symbian OS 5th ed 中通过浏览器单击 URL,我如何默认打开我的应用程序

c++ - 分发 Windows C++ 库 : how to decide whether to create static or dynamic library?

c++ - 有没有办法使用 std::copy 复制不冲突的映射值?

c++ - 什么是 libstdc++-libc 以及何时需要它

c++ - 具有已定义宏的 iOS 预处理条件导致 "token is not valid"

gcc - 将c++目标文件链接到c目标文件

Rust:在 LLVM Bitcode 中包含依赖项

c++ - 代码更改不生效