开发者

making dynamic array using Type** &x

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

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜