0

我的方法看起来像这样,在向量中编译“只读变量不可赋值”时出错。可能是什么问题?

int DownloadManager::RemoveDownload(const char *escapedTitle, const char *fileId)
{
    boost::remove_if(Core::defaultCore().GetSocketsQueue()->GetQueue(), [&](SocketConnection* socket) {
        if (strcmp(escapedTitle, socket->GetDownload()->escaped_title.c_str()) == 0 && strcmp(fileId, socket->GetDownload()->fileId.c_str()) == 0)
        {
            Core::defaultCore().GetDownloadQueue()->Remove(socket->GetDownload());

            return true;
        }

        return false;
    });

    return 0;
}

粘贴只是为了显示上面的 GetQueue() 的样子。

std::vector<SocketConnection*> GetQueue()
{
    return this->sockets_queue;
}
4

1 回答 1

1

您应该从 中返回引用GetQueue,因为现在您正试图从临时变量中删除,这是不允许的,因为remove_if第一个参数应该是引用,没有从临时变量到引用的转换。

于 2013-09-03T13:38:45.237 回答