gpt4 book ai didi

c++ - undeclared identifier 和 identifier is undefined 是什么意思?如何修复错误?

转载 作者:行者123 更新时间:2023-11-28 03:22:04 38 4
gpt4 key购买 nike

#include "stdafx.h"
#include <stdio.h>
#include <conio.h>
#include <string.h>
#include <stdlib.h>
#include <iostream>

using namespace std;

#define TIMEQUANTUM 1;
#define MAXPROCTIME 100;


struct SortList
{
int pid;
int arrivalTime;
int burstTime;
SortList *nxt;
};

struct JobList {
int pid;
int ct_arrival;
int ct_service;
int vt_served;
int vt_residence;
int vt_wait;
int vt_completion;
JobList *nxt;
};



bool initJobList(JobList *&,int *,int);
bool deinit(JobList *&);
bool doFCFS (JobList *&);
bool doRR (JobList *&);
bool doSJF(JobList *&, SortList *&);
bool doNPSJF (JobList *&);
bool doPSJF (JobList *&);
bool sortJob (JobList *&, SortList *&);

int _tmain(int argc, _TCHAR* argv[])
{

JobList *ptrJobStart;
// arrivaltime , bursttime
int arrJobs[][2] = {
{0,7},
{2,4},
{4,1},
{5,4}
};
SortList *ptrList;
initJobList (ptrJobStart,(int *)&arrJobs, (sizeof(arrJobs) / (sizeof(int)*2)));
printf("\ndoFCFS\nCPU\t\tPROCESS\n");
doFCFS (ptrJobStart);
deinit(ptrJobStart);

initJobList (ptrJobStart,(int *)&arrJobs, (sizeof(arrJobs) / (sizeof(int)*2)));
printf("\n\ndoSJF\nCPU\t\tPROCESS\n");
doSJF(ptrJobStart, ptrList);
deinit(ptrJobStart);


initJobList (ptrJobStart,(int *)&arrJobs, (sizeof(arrJobs) / (sizeof(int)*2)));
printf("\ndoRR\nCPU\t\tPROCESS\n");
doRR(ptrJobStart);
deinit(ptrJobStart);

initJobList (ptrJobStart,(int *)&arrJobs, (sizeof(arrJobs) / (sizeof(int)*2)));
printf("\ndoPSJF\nCPU\t\tPROCESS\n");
doRR(ptrJobStart);
deinit(ptrJobStart);

getch();
return 0;
}

bool doRR(JobList *&ptrJobStart)
{


if(ptrJob==NULL) return false;
JobList *ptrJobStart, *tempJobList;
ptrJobStart = ptrJob;
int maxTime = MAXPROCTIME;
int timeQuantum = TIMEQUANTUM;
bool flag = false;
ptrJobStart->vt_served = 0;
for(int processTime = 0; (processTime < maxTime) && !flag ;)
{
//check if all jobs are finished
flag = true;
tempJobList = ptrJob;
while(tempJobList!=NULL)
{
if(tempJobList->vt_served!=tempJobList->ct_service)
{
flag = false;
}
tempJobList = tempJobList->nxt;
}
}
//logic
return true;
}

bool doSJF(JobList *&ptrJobStart, SortList *&ptrList)
{
if(ptrJobStart==NULL) return false;
sortJob(ptrJobStart, ptrList);
doFCFS (ptrJobStart);
return true;
}

bool sortJob (JobList *&ptrJob, SortList *&ptrList)
{
JobList *ptrJobStart = ptrJob;
if(ptrJobStart==NULL) return false;
int maxTime = MAXPROCTIME;
SortList *newList;
ptrList = NULL;
for(; ptrJobStart!=NULL; ptrJobStart = ptrJobStart->nxt) // accumulate all arrival time = 0
{
if(ptrJobStart->ct_arrival==0)
{
if(ptrList==NULL)
{
ptrList = new SortList;
ptrList->pid = ptrJobStart->pid;
ptrList->arrivalTime = ptrJobStart->ct_arrival;
ptrList->burstTime = ptrJobStart->ct_service;
ptrList->nxt = NULL;
}
else
{
newList = new SortList;
newList->pid = ptrJobStart->pid;
newList->arrivalTime = ptrJobStart->ct_arrival;
newList->burstTime = ptrJobStart->ct_service;
newList->nxt = NULL;
ptrList->nxt = newList;
}
}
}
SortList *tempList;
tempList = ptrList;
for(int processTime = 1 ; processTime < maxTime ; processTime++) // accumulate all burst time from 1 to 100
{
ptrJobStart = ptrJob;
do
{
if((ptrJobStart->ct_arrival!=0) && (processTime == ptrJobStart->ct_service))
{
newList = new SortList;
newList->pid = ptrJobStart->pid;
newList->arrivalTime = ptrJobStart->ct_arrival;
newList->burstTime = ptrJobStart->ct_service;
newList->nxt = NULL;
tempList->nxt = newList;
tempList = tempList->nxt;
}
ptrJobStart = ptrJobStart->nxt;
}while(ptrJobStart!=NULL);
}
//sort jobs
ptrJobStart = ptrJob;
JobList *tempJobList;
tempJobList = ptrJobStart;
for(; ptrList!=NULL; ptrList = ptrList->nxt)
{
tempJobList->pid = ptrList->pid;
tempJobList->ct_arrival = ptrList->arrivalTime;
tempJobList->ct_service = ptrList->burstTime;
tempJobList = tempJobList->nxt;
}
return true;
}


bool doFCFS (JobList *& ptrJob)
{
JobList *ptrJobStart = ptrJob;
if(ptrJobStart==NULL) return false;
int maxTime = MAXPROCTIME;
ptrJobStart->vt_served = 0;
for(int processTime = 0; processTime < maxTime; processTime++)
{
if(ptrJobStart->vt_served!=ptrJobStart->ct_service)
{
ptrJobStart->vt_served+=1;
}
else
{
ptrJobStart->vt_completion = processTime;
ptrJobStart->vt_residence = processTime - ptrJobStart->ct_arrival;
ptrJobStart->vt_wait = processTime - ptrJobStart->vt_served;
cout<<"\n/* vt_served:"<<ptrJobStart->vt_served<<"\tvt_residence:"<<ptrJobStart->vt_residence
<<"\tvt_wait:"<<ptrJobStart->vt_wait<<"\tvt_completion:"<<ptrJobStart->vt_completion<<" */";
ptrJobStart = ptrJobStart->nxt;
if(ptrJobStart==NULL) break;
else
ptrJobStart->vt_served = 1;
}
cout<<"\n "<<processTime<<"\t>>\t P"<<ptrJobStart->pid;
}
return true;
}


bool deinit (JobList *& ptrJobStart) {

JobList *ptrJobDel = NULL;
do {

ptrJobDel = ptrJobStart;
ptrJobStart = ptrJobStart->nxt;
delete ptrJobDel;
}while (ptrJobStart != NULL);
return true;
}


bool initJobList(JobList*& ptrJobStart,int *pJob,int nJobs){

JobList * ptrJobs = NULL;
int i;
int j=1;

for (i=0; i<nJobs*2; i+=2) {
if (ptrJobs == NULL) {
ptrJobs = new JobList;
memset(ptrJobs,0,sizeof(JobList));
ptrJobStart = ptrJobs;
}
else {
ptrJobs->nxt = new JobList;
memset(ptrJobs->nxt,0,sizeof(JobList));
ptrJobs = ptrJobs->nxt;
}
ptrJobs->ct_arrival = *(pJob+i);
ptrJobs->ct_service = *(pJob+(i+1));
ptrJobs->pid = j;
ptrJobs->nxt = NULL;
j++;
}
return true;

此代码用于调度算法。最短作业下一个 (SJN)/最短作业优先 (SJF)(即 doSJN)正在运行。但是当我包含 doRR (do Round Robin) 时,会出现很多错误。

错误 C2065:“ptrJob”:未声明的标识符error C2082: 形式参数 'ptrJobStart 的重新定义错误 C2065:“ptrJob”:未声明的标识符错误 C2065:“ptrJob”:未声明的标识符参见“获取”的声明

我该如何解决这个问题?

最佳答案

doRR 中,参数名为 ptrJobStart。它应该是 ptrJob

您收到的错误表明,在 doRR 的第一行,ptrJob 尚未声明。

关于c++ - undeclared identifier 和 identifier is undefined 是什么意思?如何修复错误?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/15141254/

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