C++基类型到指针的转换

C++ Base Type to Pointer Conversion

本文关键字:转换 指针 基类 类型 C++      更新时间:2023-10-16

我对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指针用作指针,则它们需要保留其功能。如有任何建议,不胜感激。

您缺少new关键字:

CurrentCopy = new ClinicNode();

但你的功能需要大量的概念工作,也许你应该从这开始。例如,您正试图在void函数中返回一些内容。