"new CLASS" return CLASS 还是 CLASS*
Does "new CLASS" return CLASS or CLASS*
这可能看起来很简单,但我不知道如何实际制作一个程序来告诉我这个。
如评论所述,new
将始终为您指点。
但是正如new
所暗示的那样delete
,我强烈建议您看一下名为RAII的概念,尤其是它为何如此受欢迎。
Does "new CLASS" return CLASS or CLASS*
它 returns 指向您要分配的对象类型的指针。
The new expression attempts to allocate storage and then attempts to construct and initialize either a single unnamed object, or an unnamed array of objects in the allocated storage. The new-expression returns a prvalue pointer to the constructed object or, if an array of objects was constructed, a pointer to the initial element of the array.
这可能看起来很简单,但我不知道如何实际制作一个程序来告诉我这个。
如评论所述,new
将始终为您指点。
但是正如new
所暗示的那样delete
,我强烈建议您看一下名为RAII的概念,尤其是它为何如此受欢迎。
Does "new CLASS" return CLASS or CLASS*
它 returns 指向您要分配的对象类型的指针。
The new expression attempts to allocate storage and then attempts to construct and initialize either a single unnamed object, or an unnamed array of objects in the allocated storage. The new-expression returns a prvalue pointer to the constructed object or, if an array of objects was constructed, a pointer to the initial element of the array.