p*****g 发帖数: 445 | 1 我在code里面用了typedef定义以下
typedef state_t state_component[FC_MODES][TANK_LEVELS][BATT_LEVELS];
然后我用new新建两个指针
state_component* table1 = new state_component;
state_component* table2 = new state_component;
用vc++ 2005complie的时候报错
Error 30 error C2440: 'initializing' : cannot convert from 'state_t (*
)[256][256]' to 'state_component (*)'
但是当我把两个指针这样建立:
state_component* table1 = new state_component[1];
state_component* table2 = new state_component[1];
compile的时候就通过了。
望大牛出来传道授业解惑啊! |
t****t 发帖数: 6806 | 2 to make the explanation shorter, let's see
typedef int A[2][3][4];
A* a1=new A;
preliminary: (new int) has type int*, and (new int[10]) also has type int*.
now, A has type int[2][3][4], which means A is "array 2 of (array 3 of array
4 of int)". new A has type "pointer to (array 3 of array 4 of int)".
but A* has type "pointer to array 2 of array 3 of array 4 of int". that's a
mismatch.
but new A[1] has type "pointer to array 2 of array 3 of array 4 of int".
that's a match.
(*
【在 p*****g 的大作中提到】 : 我在code里面用了typedef定义以下 : typedef state_t state_component[FC_MODES][TANK_LEVELS][BATT_LEVELS]; : 然后我用new新建两个指针 : state_component* table1 = new state_component; : state_component* table2 = new state_component; : 用vc++ 2005complie的时候报错 : Error 30 error C2440: 'initializing' : cannot convert from 'state_t (* : )[256][256]' to 'state_component (*)' : 但是当我把两个指针这样建立: : state_component* table1 = new state_component[1];
|
p*****g 发帖数: 445 | 3 多谢。
不过对于new A has type "pointer to(array 3 of array 4 of int)"还是有点迷糊。
new int 是 int*, new int[10] 也是 int*,为什么 new A就不能简单的理解为A*呢?
多维数组一直让我很恼火啊。
array
a
【在 t****t 的大作中提到】 : to make the explanation shorter, let's see : typedef int A[2][3][4]; : A* a1=new A; : preliminary: (new int) has type int*, and (new int[10]) also has type int*. : now, A has type int[2][3][4], which means A is "array 2 of (array 3 of array : 4 of int)". new A has type "pointer to (array 3 of array 4 of int)". : but A* has type "pointer to array 2 of array 3 of array 4 of int". that's a : mismatch. : but new A[1] has type "pointer to array 2 of array 3 of array 4 of int". : that's a match.
|
z****e 发帖数: 2024 | 4 master shifu!
array
a
【在 t****t 的大作中提到】 : to make the explanation shorter, let's see : typedef int A[2][3][4]; : A* a1=new A; : preliminary: (new int) has type int*, and (new int[10]) also has type int*. : now, A has type int[2][3][4], which means A is "array 2 of (array 3 of array : 4 of int)". new A has type "pointer to (array 3 of array 4 of int)". : but A* has type "pointer to array 2 of array 3 of array 4 of int". that's a : mismatch. : but new A[1] has type "pointer to array 2 of array 3 of array 4 of int". : that's a match.
|
X****r 发帖数: 3557 | 5 因为new 和new []是两个不同的operator,只是共用了同一个keyword而已。
比如说你重载new ,不影响现有的new []
【在 p*****g 的大作中提到】 : 多谢。 : 不过对于new A has type "pointer to(array 3 of array 4 of int)"还是有点迷糊。 : new int 是 int*, new int[10] 也是 int*,为什么 new A就不能简单的理解为A*呢? : 多维数组一直让我很恼火啊。 : : array : a
|
z****e 发帖数: 2024 | 6 又见红猪侠。
你这个版主真是清水衙门呀。
【在 X****r 的大作中提到】 : 因为new 和new []是两个不同的operator,只是共用了同一个keyword而已。 : 比如说你重载new ,不影响现有的new []
|