你可以删除一个指针而不用新的吗? [英] Can you delete a pointer without newing it up?
本文介绍了你可以删除一个指针而不用新的吗?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
大家好,
如果我不是新手指针,可以删除吗?
见下面的代码:
void A :: foo()
{
char * buffer;
删除缓冲区;
返回;
}
问候,
Vynce
Hi all,
If I don''t new up a pointer, can I delete it?
see code below:
void A::foo()
{
char* buffer;
delete buffer;
return;
}
regards,
Vynce
推荐答案
asimorio写道:
asimorio wrote:
大家好,
如果我不是新手指针,我可以删除吗?
嗯,你可以,但是除非指针是一个
空指针,否则行为将是未定义的。在这种情况下,什么也没做。
见下面的代码:
void A :: foo()
{
char * buffer;
删除缓冲区;
返回;
}
Hi all,
If I don''t new up a pointer, can I delete it?
Well, you can, but the behavior will be undefined unless the pointer was a
null pointer. In that case, nothing is done.
see code below:
void A::foo()
{
char* buffer;
delete buffer;
return;
}
asimorio写道:
asimorio wrote:
大家好,
如果我不是新手指针,可以删除它吗?
看下面的代码:
void A :: foo()
{
char * buffer;
删除缓冲区;
Hi all,
If I don''t new up a pointer, can I delete it?
see code below:
void A::foo()
{
char* buffer;
delete buffer;
您可以尝试,但您的厕所可能会爆炸。
-
Ian Collins。
You can try, but your toilet might explode.
--
Ian Collins.
asimorio写道:
asimorio wrote:
大家好,
如果我不是新手指针,我可以删除它吗?
看下面的代码:
void A :: foo()
{
char *缓冲区;
删除缓冲区;
返回;
}
Hi all,
If I don''t new up a pointer, can I delete it?
see code below:
void A::foo()
{
char* buffer;
delete buffer;
return;
}
不,你不能,你的行为>
删除缓冲区;
未定义。
什么这个代码的目的究竟是什么?
No you can''t, the behaviour of your
delete buffer;
is undefined.
What exactly is the purpose of that code?
这篇关于你可以删除一个指针而不用新的吗?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文