我在C ++中有点生疏,我遇到了Queue类的问题。基本上我不能从类类型转换为指针(这是有道理的,但我需要完成类似的事情)。
以下是一个例子:
void ClinicQueue::removeFront()
{ // Start of removeFront
ClinicNode* Penultimate;
ClinicNode* Current;
ClinicNode* CurrentCopy;
CurrentCopy = ClinicNode();//Cannot convert ClinicNode to ClinicNode* in assignment
if (back == front)
{
Current = front;
CurrentCopy->modify(Current); //No matching function
//(wants a ClinicNode arg not ClinicNode*)
front = back = NULL;
delete Current;
}
else
{
Penultimate = back;
while (Penultimate -> next != front) Penultimate = Penultimate -> next;
Current = front;
Penultimate -> next = NULL;
CurrentCopy->modify(Current);//No matching function
//(wants a ClinicNode arg not ClinicNode*)
delete Current;
front = Penultimate;
}
size--;
} // End of removeFront
我需要的是保持相同的功能,同时避免非法转换....即ClinicNode指针需要保留其功能,如果它们不再被用作指针。非常感谢任何建议。
答案 0 :(得分:4)
您错过了new
关键字:
CurrentCopy = new ClinicNode();
但是你的功能需要大量的概念性工作,也许你应该从那开始。例如,你试图在void函数中返回一些东西。