我想插入一些东西到链接列表中,但编译器告诉我,我无法从const Student*
转换为Student*
。 每个节点包含一个Student *stud
和一个Node *next
。这是我迄今为止功能的书面:如何将const Class *转换为Class *?
void LinkedList::putAtTail(const Student &student){
Node *p = new Node();
p->stud = &student; //this is where I have trouble
p->next - NULL;
//then insert `p` into the Linked List
}
编译器不希望编译这个,给我error: invalid conversion from ‘const Student*’ to ‘Student*’
。
我该如何解决这个问题,而不改变我的putAtTail(const Student &student)
函数的参数?
请显示Node的声明。 –
因为'&student'在这方面与'student'完全不同。 –
你可能想要添加一个参数的副本。 –