关于传参时参数值改变
//Line 结构体的定义typedef struct Line {
struct Stop *firstStop;
int size;
int capacity;
int maxCapacity;
Line(Stop *firstStop) {
this->firstStop = firstStop;
this->size = 0;
this->capacity = 0;
this->maxCapacity = 100;
}
/*
*/
};
//给Line赋值并打印
Line* distributeLine(Consumer* consumers,int num) {
Line* lines = (Line*)malloc(sizeof(Line) * num); //给线路分配内存
int availableNum = num; //剩余未被分配的客户数量
Stop* firstStop = (Stop*)malloc(sizeof(Stop));
//Line lines[50];
int i = 0;
while (availableNum >0) { //循环分配线路
lines[i]= findStops(consumers,num); //将一组客户分配给第i条线路
print(lines[i]);
/*
firstStop=lines[i].firstStop;
int j = 0;
firstStop->print();
while (j < lines[i].size) {
Stop* stop = firstStop->nextStop;
stop->print();
j++;
}
*/
//print(firstStop,lines[i].size);
availableNum -= lines[i].size; //未被分配的客户数量-第i条线路的客户数量
i++;
}
return lines;
}
//这是用于打印结构体Line的方法
void print(Line l){
Line line = l;
int i = 0;
Stop* stop = l.firstStop;
print(*stop);
while (i < l.size) {
stop = stop->nextStop;
print(*stop);
i++;
}
}
问题是当我单步刚进入到print方法时,形参就是我传入的参数,可是当我执行到下一步操作时,参数 l 却变成了一个莫名其妙的值,有大佬能帮我解决吗?感激不尽!!
[此贴子已经被作者于2021-3-7 22:29编辑过]