- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
我正在尝试遍历双端队列并删除到达时间最小的元素。该函数在前几次工作,然后给我“迭代器不可取消引用”错误并停止工作。
我的Processor.h
:
#pragma once
#include <deque>
#include "Job.h"
#include <ctime>
using namespace std;
class Processor {
public:
deque<Job> priorityQueue;
Job runningJob;
bool isProcessing;
int processingTime;
int runningTime;
int overallJobs;
int numJobs[4]; //0 is A, 1 is B, 2 is C, 3 is D
int runningJobNumber;
int interruptedJobs;
Processor();
void simulate();
Job findNextJob();
};
我的findNextJob()
:
Job Processor::findNextJob() {
Job nextJob = priorityQueue.front();
deque<Job>::const_iterator iter = priorityQueue.begin();
deque<Job>::const_iterator location;
while (iter <= priorityQueue.end()) {
if (iter->arrivalTime < nextJob.arrivalTime) {
nextJob = *iter;
location = iter;
iter++;
}
else {
iter++;
}
}
priorityQueue.erase(location);
return nextJob;
}
最后,我调用函数的地方:
void Processor::simulate() {
srand(time(NULL));
char newJobType;
while (processingTime <= 50) {
newJobType = 65 + rand() % 4;
Job newJob(newJobType);
newJob.arrivalTime += runningTime;
processingTime += newJob.processingTime;
priorityQueue.push_back(newJob);
cout << endl << newJob.type << " " << newJob.arrivalTime;
runningTime++;
}
runningTime = 0;
int jobFinishTime;
Job nextJob;
nextJob = findNextJob();
while (priorityQueue.size()) {
cout << endl << runningTime << ") " << "Queue size: " << priorityQueue.size();
if (!isProcessing) {
cout << " CPU 1 Idle;";
if (nextJob.arrivalTime == runningTime) {
runningJob = nextJob;
//irrelevant code here
nextJob = findNextJob();
}
}
if (isProcessing && (runningJob.arrivalTime + runningJob.processingTime) != runningTime) {
//irrelevant code here
if (nextJob.arrivalTime <= runningTime) {
runningJob = nextJob;
//irrelevant code here
nextJob = findNextJob();
}
}
if (nextJob.priority > runningJob.priority && nextJob.arrivalTime <= runningTime) {
//irrelevant code here
}
runningTime++;
}
}
findNextJob()
成功运行了两到三次,然后给出了错误。任何帮助将不胜感激。
最佳答案
在 C++ 中,结束迭代器“指向”最后一个元素之后的一个。
findNextJob 允许迭代器 iter
变得等于 priorityQueue.end()
,因此取消引用它是无效的。
while (iter <= priorityQueue.end()) {
// ...
}
关于c++ - "Deque iterator not dereferencable"错误,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/55669716/
我正在使用一个库 - HtmlUnit - 并且我刚刚从版本 2.4 更新到版本 2.5。当我针对 2.5 编译代码时,我收到一条我不熟悉的奇怪对象“无法取消引用”错误消息。此外,我不明白为什么当我用
我有 C 和 C++ 背景,一直认为 Java 中的解引用是通过对象的引用访问对象的过程。 例如“ref”是一个引用,当用于访问它所引用的Integer对象时,它被解引用: Integer r
这个问题已经有答案了: int cannot be dereferenced (3 个回答) 已关闭 9 年前。 我正在编写一个简单的 Java 程序来进行温度转换,并且在第 8 行(我已在下面的代码
请在说明中包含一个示例。 最佳答案 回顾基本术语 通常情况下就足够了 - 除非您正在编写程序集 - 设想一个 指针包含一个数字内存地址,其中 1 表示进程内存中的第二个字节,2 表示第三个字节,3 表
本题将从草稿N1570中获取信息,所以基本上是C11。 通俗地说,取消引用指针意味着将一元 * 运算符应用于指针。草稿文件中只有一处存在“取消引用”一词(没有“取消引用”的实例),并且位于脚注中: 1
我有这三个文件。使用结构体、函数和指针。 尝试这样做: void getName(Name *) - 接收指向名称的指针并执行操作 联系人.h struct Name { char firstNam
好的,所以我需要生成 7 个 1 到 100 之间的随机数,并将最大值打印在屏幕上。但是,当我编译此代码时: public class ArrayofTemperatures { public
我喜欢代码让我头疼的时候。除了这个。我只是使用一种常用的算法用随机 double 填充一个 vector 。问题是,在编译之后,它给了我一个“Iterator not dereferenceable”
我有 C 和 C++ 背景,一直认为 Java 中的解引用是通过对象的引用访问对象的过程。 例如“ref”是一个引用,当用于访问它所引用的Integer对象时,它被解引用: Integer r
本题将从草稿中抽取信息N1570 ,所以 C11 基本上。 通俗地说,取消引用指针意味着将一元 * 运算符应用于指针。文档草案中只有一个地方存在“取消引用”一词(没有“取消引用”的实例),并且在脚注中
我正在尝试实现一个提供 map 标记动画的库,但是当我尝试添加一些高级方法时,它在第二个“.withFillColor(Color.BLUE)”上抛出一个错误,其中显示:错误: void 无法取消引用
我收到以下代码的“int 无法取消引用”错误。任何帮助表示赞赏。谢谢: public int value() { int total = 0; **for (int i = 0; i < wallet
编译时我似乎收到“错误:int 无法取消引用”错误。我已经查找了发生这种情况的原因,尽管如此,我不确定如何解决它。 public class NetID_BaseballPitcher { S
这是我遇到问题的地方。 double num1 = Math.random(); double num2 = Math.random(); if (num1 < num2.nu
所以,我花了一些时间编写一些计算方法,以便在我正在尝试制作的角色扮演游戏的预览战斗窗口中获取一些导入数字(有人还记得《火焰纹章》吗?这是它的简化版本)。这是我尝试从这些 c 形成 jtable 的地方
我问的问题非常基础,但我试图通过在编译器中做练习来理解 C++ 中指针的行为。因此,例如,我首先声明一个 int 指针 *p 并尝试为其赋予一些值并打印它: #include using names
这里我有一些值,其中两个是整数,我不能对它们调用方法,因为它们不是引用。我该如何解决这个问题? String srcAddr, dstAddr, protocol; int srcPort, dstP
我有以下代码部分,它给出了明确的 null 取消引用。 uint64_t *var1 = NULL; char *var2 = NULL; //Alias transfer var1 = (uint6
在 C 中,是否可以为取消引用的指针定义别名/快捷方式? 即假设定义如下: void * ptr_to_my_variable = 0x2ff00000; 是否可以定义一个对应于 *ptr_to_my
假设我有这样的东西: class Collection { private: typedef std::vector >::iterator Iterator; std::vector
我是一名优秀的程序员,十分优秀!