Iterator

// JobQueue.h

#ifndef _JOBQUEUE_H

#define _JOBQUEUE_H

#include "Job.h"

#include <vector>

using namespace std;

class JobQueue {

public:

JobQueue();

void addQueue(const Job & myJob);

private:

Job jobList;

public:

vector<Job>* getQueue();

};

#endif

說明

    • 設計單獨物件處理陣列訪問。
    • JobQueue 是含有 Job 陣列之物件。
    • IteratorJob 是處理 JobQueue 陣列訪問之物件。

// IteratorJob.h

#ifndef _ITERATORJOB_H

#define _ITERATORJOB_H

#include <vector>

using namespace std;

class Job;

class IteratorJob {

public:

IteratorJob(const vector<Job> * jobQueue);

Job* begin();

Job* end();

Job* next();

private:

int currentPos;

};

#endif