Hello,
I have some difficulties in understanding initializing vector of queues. Here is my code.
The output is:
push to queue 0
push to queue 0
push to queue 1
push to queue 1
push to queue 2
push to queue 2
finish initialize
call GetEmployee
start to pop
Then it crashes when trying to access the eq1[i].
Thank you very much if someone can point out the problem..
June
I have some difficulties in understanding initializing vector of queues. Here is my code.
Code:
#include <queue> #include <vector> #include <iostream> using namespace std; class Employee { public: Employee(){}; }; typedef queue<Employee*> EmployeeQueue; typedef vector<EmployeeQueue*> QueueArray; #define MAX 3 #define Elem 2 class CallCenter { public: CallCenter(){ QueueArray eq1 = QueueArray(MAX); for(int i = 0; i < MAX; ++i){ eq1[i] = new EmployeeQueue(); for(int j = 0; j < Elem; ++j) { Employee *e = new Employee(); eq1[i]->push(e); cout << "push to queue " << i << endl; } } cout << "finish initialize" << endl; } void GetEmployee() { cout << "start to pop" << endl; for(int i = 0; i < MAX; ++i){ while(!eq1[i]->empty()) { cout << "pop queue i "; eq1[i]->pop(); } } } private: QueueArray eq1; }; int main() { CallCenter *cc = new CallCenter(); cout << "call GetEmployee" << endl; cc->GetEmployee(); system("pause"); return 0; }
push to queue 0
push to queue 0
push to queue 1
push to queue 1
push to queue 2
push to queue 2
finish initialize
call GetEmployee
start to pop
Then it crashes when trying to access the eq1[i].
Thank you very much if someone can point out the problem..
June
Comment