如何创建一个指针数组? [英] How do I create an array of pointers?
本文介绍了如何创建一个指针数组?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我想创建一个指针数组。这些指针会指向我创建了一个Student对象。我该怎么做?
我现在拥有的是:
学生* DB =新的学生[5];
但是,阵列中的每个元素是学生对象,而不是指针学生对象。
谢谢你。
解决方案
学生** DB =新的学生* [5];
//静态分配的:
学生*分贝[5];
I am trying to create an array of pointers. These pointers will point to a Student object that I created. How do I do it? What I have now is:
Student * db = new Student[5];
But each element in that array is the student object, not a pointer to the student object. Thanks.
解决方案
Student** db = new Student*[5];
// To allocate it statically:
Student* db[5];
这篇关于如何创建一个指针数组?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文