是**和* []相同? [英] Are ** and * [] the same?

查看:163
本文介绍了是**和* []相同?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有我的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 [][] and T ** 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 to T whereas T** has type pointer to pointer to T. 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* and int[] aren't the same type, but when you write a function that takes an int[] parameter, it's adjusted so that it takes an int* parameter. (Note that this adjustment is suppressed if the parameter is a reference to array.)

Are T [][] and T ** 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 is T* p_proc[].

这篇关于是**和* []相同?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆