是**和* []相同? [英] Are ** and * [] the same?
问题描述
我有我的Eclipse IDE这对声明/定义(在.h和.HPP分别):
A(T * []);
和
A< T> ::一(T ** p_proc){...}
首先是一个指针数组,指针的其它的指针。
我很困惑,因为它们是可以互换位置; Eclipse的抱怨,如果我替换 **
按 * []
,抛出一个语法错误。当我做相反,虽然Eclipse不引发错误。
我的问题是双重的;有这两个符号基本上是相同的?是 T [] []
和 T **
一样吗?
为什么Eclipse中抛出一个语法错误时,HPP文件的类型为 * []
,但不是在头?</ P>
我的问题是双重的;有这两个符号基本上是相同的?
块引用>没有,他们不是。
T * []
已输入的指针的未知大小的数组T
的,而T **
的类型为的指针的指针的T
的。数组和指针的不可以相同的一般。不过,声明的功能参数的是数组类型是完全相同宣布它是相应的指针类型。如果指定一个函数的参数有那么数组类型,它的调整,以有相应的指针类型。以同样的方式,
为int *
和INT []
是不是同一类型,但是当你写一个函数这需要一个INT []
参数,它的调整,它需要一个为int *
参数。 (请注意,本次调整燮pressed如果该参数是一个的参考的数组。)
是
T [] []
和T **
一样呢?
块引用>实际上
T [] []
是不是有效的类型都没有。多维数组类型,只有的第一个的绑定可以被省略。
为什么Eclipse中抛出一个语法错误时,HPP文件的类型为
* []
,但不是在头?</ P>
块引用>大概是因为你写的
T * [] p_proc
。正确的声明部分为T * p_proc []
。I have this pair of declaration/definition on my Eclipse IDE (in a .h and .hpp respectively):
A( T* [] );
and
A<T>::A(T ** p_proc) { ... }
The first is an array of pointers, the other a pointer of pointers. I am confused in that they are interchangeable here; Eclipse complains if I replace the
**
by* []
, throwing a syntax error. Eclipse does not raise errors when I do the opposite, though.My question is twofold; are these two notations fundamentally the same? Are
T [][]
andT **
the same as well? Why does Eclipse throw a syntax error when the hpp file has a type of* []
, but not in the header?解决方案My question is twofold; are these two notations fundamentally the same?
No, they are not.
T*[]
has type array of unknown size of pointer toT
whereasT**
has type pointer to pointer toT
. Arrays and pointers are not identical in general.However, declaring a function parameter to be of array type is exactly the same as declaring it to be of the corresponding pointer type. If a function parameter is specified to have array type then it's "adjusted" to have the corresponding pointer type. In the same way,
int*
andint[]
aren't the same type, but when you write a function that takes anint[]
parameter, it's adjusted so that it takes anint*
parameter. (Note that this adjustment is suppressed if the parameter is a reference to array.)Are
T [][]
andT **
the same as well?Actually
T[][]
is not a valid type at all. In a multidimensional array type, only the first bound may be omitted.Why does Eclipse throw a syntax error when the hpp file has a type of
* []
, but not in the header?Probably because you're writing
T*[] p_proc
. The correct declarator isT* p_proc[]
.这篇关于是**和* []相同?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!