如何返回指向链表前端节点的指针? [英] How do I return a pointer to the front node of a linked list?
问题描述
您好,我有这个小问题...
我正在编写一个行车道并创建了一个名为getFront()的函数,假设它返回指向车道前方的汽车。
不写所有代码,所以我只写下面的要点......
Hello, I have this minor problem...
I am programming a traffic lane and made a function called getFront(), which is suppose to return the pointer to the car at the front of the lane.
Not writing all the codes so I just wrote the main points below...
const Vehicles * TrafficSingleLane::getFront() const {
const Vehicles * car;
car = head;
if (head != NULL) {
return head;
}else return 0;
return 0;
}
所以我得到的错误是:无法将'TrafficSingleLane :: myNode * const'转换为'const Vehicles *。问题出在car = head部分......我不想知道代码,但想知道解决这个问题的步骤和建议,所以我可以自己试试。
我尝试了什么:
我没有使用这些代码,而是尝试了
So the error I am getting is: Cannot convert 'TrafficSingleLane::myNode * const' to 'const Vehicles *'. The problem is with the "car = head" part... I do not want to know the codes but wanting to know the steps and advice to fix this problem so I can try it myself.
What I have tried:
Instead of having those codes, I have tried
const Vehicles * TrafficSingleLane::getFront() const {
return head;
}
但是有类似的错误。我在getFront()之前有其他函数创建链表
But has similar error. I do have other functions before getFront() which creates the linked list
推荐答案
head $ c $之间没有简单的转换c>和汽车
类型。可能你应该发布相关的声明。
There is no trivial conversion between thehead
andcar
types. Probably you should post the relevant declarations.
这篇关于如何返回指向链表前端节点的指针?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!