[英]Allocating space for an array
I have a C++ program that dynamically allocates an array of integers. 我有一个C ++程序,可以动态分配整数数组。 In the final function below I can't figure out how to allocate space for the array, new int[*arrPtr];
在下面的最后一个函数中,我无法弄清楚如何为数组分配空间, new int[*arrPtr];
is what I had in mind after reading the chapter on pointers, and it compiles properly, but the program crashes. 是我阅读了有关指针的章节后想到的,它可以正确编译,但是程序崩溃。 Could anyone take a look at my code and point me in the right direction? 谁能看看我的代码并为我指出正确的方向?
I greatly appreciate any assistance on this matter, thank you very much for your time. 非常感谢您提供的任何帮助,非常感谢您的宝贵时间。
It's not 不是
new int[*arrPtr]
It's 它的
arrPtr = new int[num]; //num is the size of the array.
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.