“新的" C ++中的运算符,指针问题 [英] the "new" operator in c++, pointer question
本文介绍了“新的" C ++中的运算符,指针问题的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
愚蠢的问题,但是每当您调用new时,您总会有一个指针吗?
SomeClass *person = new SomeClass();
那是因为您需要一个指针来指向为SomeClass变量人员分配的新内存空间吗?谢谢!
解决方案
如果new
成功完成,它将始终返回一个指针(如果未成功完成,将引发异常,并且不返回任何内容). /p>
该指针指向创建的对象,对于数组,则指向该数组第一个元素的指针.
Dumb question, but whenever you call new, do you always have a pointer?
SomeClass *person = new SomeClass();
And is that because you need a pointer to point to that new space of memory that was allocated for the SomeClass variable person? Thanks!
解决方案
If new
completes successfully, it always returns a pointer (if it doesn't complete successfully, an exception is thrown, and nothing is returned).
The pointer is to the object that was created, or in the case of an array, a pointer to the first element of the array.
这篇关于“新的" C ++中的运算符,指针问题的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文