可能重复:
如何将对象传递给 C++ 中的函数?
主班
#include "List.h"
#include "Car.h"
#include "Worker.h"
#include "Queue.h"
#include <iostream>
#include <string>
using namespace std;
void initWorkerList(List<Worker>);
void initCarList(List<Car>, Queue, Queue);
int main() {
List<Worker> WorkerList;
List<Car> CarList;
Queue q1, q2;
initWorkerList(WorkerList);
initCarList(CarList, q1, q2); // Error here
//..... e.g cout << "Successful!"; but it does not displays it...
}
void initWorkerList(List<Worker> WorkerList) {
Worker w1 = Worker("Ben Ang", "Ben123", "pass123", 'M');
WorkerList.add(w1);
Worker w2 = Worker("Grace Eng", "Gr4ce", "loveGrace", 'W');
WorkerList.add(w2);
Worker w3 = Worker("Rebecca Xuan", "Xuanz", "Rebecca Xuan", 'W');
WorkerList.add(w3);
}
void initCarList(List<Car> CarList, Queue q1, Queue q2) {
Car c1 = Car("SJS1006Z","Toyota", "Saloon car");
Car c2 = Car("SFW6666E", "hyundai", "Taxi (Saloon)");
Car c3 = Car("SCF1006G","Mercedes", "Large Van");
Car c4 = Car("SBQ1006Z", "Puma", "Saloon Car");
q1.enqueue(c1);
q2.enqueue(c1);
q2.enqueue(c3);
q1.enqueue(c4);
q1.enqueue(c1);
q1.enqueue(c1);
q1.enqueue(c1);
q2.enqueue(c2);
q2.enqueue(c2);
}
根本没有错误。但是在调试时没有显示任何内容...我已经尝试过,我的猜测是 initCarList(CarList,q1,q2); 有问题 因为在该代码之后,其他代码完全可以工作。有什么问题吗?谢谢