开发者

making dynamic array using Type** &x

开发者 https://www.devze.com 2023-04-11 21:50 出处:网络
With respect to the following code snippet for making a dynamic array 开发者_C百科template <class Type>

With respect to the following code snippet for making a dynamic array

开发者_C百科template <class Type> 
void Make2DArray(Type** &x,int rows, int cols) 
{ x=new Type*[rows]; 
   for (int i=0;i<rows;i++) x[i]=new Type[cols]; 
}

How to understand the usage of Type** &x, why it has two **


Type** is a pointer to a pointer.

Type**& is a reference to a pointer which points to a pointer.

** will allow you to make an array of an arrays. This can be used for 2d arrays - x[][] will work.

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号