C++基类型到指针的转换
C++ Base Type to Pointer Conversion
我对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函数中返回一些内容。
相关文章:
- 转换指针引用的字符串
- 无法向上转换指针到指针参数
- 混合转换指针和引用
- 堆栈对象的强制转换指针
- 基类到派生模板类的强制转换指针,而不知道类型
- 删除类型转换指针的最佳方法
- 管理到本机值类转换:强制转换指针是否安全?
- 转换指针类型
- 为什么函数不能正确强制转换指针(从基类到派生类)
- 当我们递增下面的类型转换指针时会发生什么?
- 类型强制转换指针构造函数调用
- 如何转换(指针向量)-->(指向指针数组的指针)
- 如何从类功能转换指针
- 在C++对象中:我应该使用父类强制转换指针,还是应该使用实际类本身进行强制转换
- Delphi中的类型转换指针添加
- C++分段错误(核心转储)错误 - 强制转换指针/将函数值返回到线程
- 以C++和运算符优先级键入指向数组成员的强制转换指针
- C++动态强制转换指针的内存清理
- 转换指针和引用的好处
- 在c++中转换指针