i****d 发帖数: 255 | 1 int a[3][3], **pta;
pta = &a[0]; // why wrong? How to correct?
subprogram(pta); |
S**I 发帖数: 15689 | 2 Change declaration of pta to:
int (*pta)[3]
【在 i****d 的大作中提到】 : int a[3][3], **pta; : pta = &a[0]; // why wrong? How to correct? : subprogram(pta);
|
i****d 发帖数: 255 | 3 Thanks so much!
My problem is that subprogram(pta) is a third-part program that only
accepts a double pointer **pta. How can we do to match it?
【在 S**I 的大作中提到】 : Change declaration of pta to: : int (*pta)[3]
|
S**I 发帖数: 15689 | 4 change declaration of a to int *a[3]
【在 i****d 的大作中提到】 : Thanks so much! : My problem is that subprogram(pta) is a third-part program that only : accepts a double pointer **pta. How can we do to match it?
|
a**e 发帖数: 64 | 5 Or something ugly:
pta = new int* [3];
for( int i = 0; i < 3; i++ )
pta[i]=a[i]; |
i****d 发帖数: 255 | 6 Thank you SETI and aaee!
【在 a**e 的大作中提到】 : Or something ugly: : pta = new int* [3]; : : for( int i = 0; i < 3; i++ ) : pta[i]=a[i];
|
t****t 发帖数: 6806 | 7 pointer to pointer is totally different from 2-dimensional array. DO NOT MIX
THEM.
【在 i****d 的大作中提到】 : Thank you SETI and aaee! : :
|
b***i 发帖数: 3043 | 8 对,这样也许就是楼主的第三方程序需要的,是动态分配的指针的指针的内存。
而且,这样也不算ugly,这就是标准动态分配二维均可变数组的方法。
【在 a**e 的大作中提到】 : Or something ugly: : pta = new int* [3]; : : for( int i = 0; i < 3; i++ ) : pta[i]=a[i];
|