由买买提看人间百态

boards

本页内容为未名空间相应帖子的节选和存档,一周内的贴子最多显示50字,超过一周显示500字 访问原贴
Programming版 - typedef and operator new problem
相关主题
多线程优化求助! (转载)how to initialize this struct.
怎么样实现fuzzy joinsize不固定的struct怎么定义呀?
SQL add some columns into a table from another table (转载stack/heap corruption
error of sql query in MS Access database (转载)a weak c question, how to pass an array into a function?
Error of SQL query on IBM netezza SQL database from Aginity (转载)An algorithm question
sqlite3 db.close() called before db.serialized() finishes谁给解释一下这个c question
C++ array new一问Is there anything wrong with this C++ array initialization?
C++里get array size的问题 (转载)问一个 char * 和 char [] 的问题
相关话题的讨论汇总
话题: component话题: new话题: array话题: state话题: int
进入Programming版参与讨论
1 (共1页)
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 []

1 (共1页)
进入Programming版参与讨论
相关主题
问一个 char * 和 char [] 的问题Error of SQL query on IBM netezza SQL database from Aginity (转载)
能帮我看看Ruby的这道题吗?sqlite3 db.close() called before db.serialized() finishes
问一个leetcode的排序问题C++ array new一问
a simple questionC++里get array size的问题 (转载)
多线程优化求助! (转载)how to initialize this struct.
怎么样实现fuzzy joinsize不固定的struct怎么定义呀?
SQL add some columns into a table from another table (转载stack/heap corruption
error of sql query in MS Access database (转载)a weak c question, how to pass an array into a function?
相关话题的讨论汇总
话题: component话题: new话题: array话题: state话题: int