元素数量是一个数组 [英] Number of elements is an array

查看:85
本文介绍了元素数量是一个数组的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

假设我的代码中有一行代码如下(注意:点是

__value类System :: Drawing :: Point):


点[] =新点[3];


我现在如何''''''指出''它有多少元素(在这种情况下是答案

是3)?


这不起作用:


int element_count = sizeof(point); //错误C3608:不能将sizeof应用于

__gc数组


提前致谢!!! :)


[== P ==]

Say I have a line in my code something like the following (NOTE: Point is
__value class System::Drawing::Point):

Point point[] = new Point[3] ;

How do I now ''ask'' ''point'' how many elements it has (in this case the answer
is 3)?

This does NOT work:

int element_count = sizeof(point) ; // error C3608: can''t apply sizeof to a
__gc array

Thanks in advance!!! : )

[==P ==]

推荐答案

当然,一个明显的解决方案是做类似的事情:


#define POINT_ARRAY_SZ 3

点数[] =新点[POINT_ARRAY_SZ];


然后你就可以随意使用它。


Tom

< PO ******* @ RoundTripInc.com>在消息中写道

新闻:eQ ************* @ TK2MSFTNGP10.phx.gbl ...
Of course, an obvious solution is to do something like:

#define POINT_ARRAY_SZ 3

Point point[] = new Point[POINT_ARRAY_SZ];

Then you could use it anywhere you want.

Tom

"Peter Oliphant" <po*******@RoundTripInc.com> wrote in message
news:eQ*************@TK2MSFTNGP10.phx.gbl...
说我有一行我的代码如下所示(注意:点是
__value类System :: Drawing :: Point):

Point point [] = new Point [3];
< br>我现在怎么''''''点''它有多少元素(在这种情况下
答案是3)?

这不起作用:

int element_count = sizeof(point); //错误C3608:不能将sizeof应用于__gc阵列

提前致谢!!! :)

[== P ==]
Say I have a line in my code something like the following (NOTE: Point is
__value class System::Drawing::Point):

Point point[] = new Point[3] ;

How do I now ''ask'' ''point'' how many elements it has (in this case the
answer is 3)?

This does NOT work:

int element_count = sizeof(point) ; // error C3608: can''t apply sizeof to
a __gc array

Thanks in advance!!! : )

[==P ==]



point->长度


Peter Oliphant < PO ******* @ RoundTripInc.com>在消息中写道

新闻:eQ ************* @ TK2MSFTNGP10.phx.gbl ...
point->Length

"Peter Oliphant" <po*******@RoundTripInc.com> wrote in message
news:eQ*************@TK2MSFTNGP10.phx.gbl...
说我有一行我的代码如下所示(注意:点是
__value类System :: Drawing :: Point):

Point point [] = new Point [3];
< br>我现在怎么''''''点''它有多少元素(在这种情况下
答案是3)?

这不起作用:

int element_count = sizeof(point); //错误C3608:不能将sizeof应用于__gc阵列

提前致谢!!! :)

[== P ==]
Say I have a line in my code something like the following (NOTE: Point is
__value class System::Drawing::Point):

Point point[] = new Point[3] ;

How do I now ''ask'' ''point'' how many elements it has (in this case the
answer is 3)?

This does NOT work:

int element_count = sizeof(point) ; // error C3608: can''t apply sizeof to
a __gc array

Thanks in advance!!! : )

[==P ==]



> #define POINT_ARRAY_SZ 3
> #define POINT_ARRAY_SZ 3

点数[] =新点[POINT_ARRAY_SZ];

然后你可以在任何你想要的地方使用它。


嗨汤姆,


我看到你在说什么,但我需要的是能够找到

*任意*数组中的元素数量。换句话说,当数组中的元素数量是在运行时定义的并且是变量时。


这正是我想要的要做的事情:


int Array_Size(Point point [])

{

return number_of_elements_in(point);

}


为了把它放在上下文中,我正在使用Graphics DrawPolygon方法。这里它是
作为参数Point [],多边形的顶点列表。但是

函数不会将Point []中的元素数作为参数,

因此DrawPoygon()必须能够计算出<中的元素数量br />
仅从Point []指向[](而不是实例)。我需要能够同样地执行

,因为我必须先处理这些点才能将它们交给

DrawPolygon,所以当然我需要知道元素的数量。点[]

以及相同的信息(即,我没有给出点数组大小

元素数量)。

Tom Serface < TS ****** @ msn.com>在消息中写道

新闻:%2 **************** @ tk2msftngp13.phx.gbl ...当然,一个明显的解决方案是做某事喜欢:

#define POINT_ARRAY_SZ 3

点点[] =新点[POINT_ARRAY_SZ];

然后你可以在任何你想要的地方使用它。

Tom

Peter Oliphant < PO ******* @ RoundTripInc.com>在消息中写道
新闻:eQ ************* @ TK2MSFTNGP10.phx.gbl ...

Point point[] = new Point[POINT_ARRAY_SZ];

Then you could use it anywhere you want.
Hi Tom,

I see what you''re saying, but what I need is the ability to find out the
number of elements in an *arbitrary* array. Put another way, when the number
of elements in the array is defined at runtime and is a variable.

This is exactly what I want to be able to do:

int Array_Size( Point point[] )
{
return number_of_elements_in( point ) ;
}

To put this in context, I''m using the Graphics DrawPolygon method. Here it
takes as a parameter Point[], the list of the vertices of the polygon. But
the function does not take the number of elements in Point[] as a parameter,
hence DrawPoygon() must be able to figure out the number of elements in
Point[] just from Point[] (rather, an instance of). I need to be able to do
the same since I must process these points before I give them to
DrawPolygon, so of course I need to know the number of elements in Point[]
as well from the same info (i.e., I''m not given the Point array size in
number of elements).
"Tom Serface" <ts******@msn.com> wrote in message
news:%2****************@tk2msftngp13.phx.gbl... Of course, an obvious solution is to do something like:

#define POINT_ARRAY_SZ 3

Point point[] = new Point[POINT_ARRAY_SZ];

Then you could use it anywhere you want.

Tom

"Peter Oliphant" <po*******@RoundTripInc.com> wrote in message
news:eQ*************@TK2MSFTNGP10.phx.gbl...
说我的代码中有一行代码以下(注意:点是
__value类System :: Drawing :: Point):

点数点[] =新点[3];

如何我现在要问''''点''它有多少元素(在这种情况下
答案是3)?

这不起作用:

int element_count = sizeof(point); //错误C3608:不能将sizeof应用于__gc阵列

提前致谢!!! :)

[== P ==]
Say I have a line in my code something like the following (NOTE: Point is
__value class System::Drawing::Point):

Point point[] = new Point[3] ;

How do I now ''ask'' ''point'' how many elements it has (in this case the
answer is 3)?

This does NOT work:

int element_count = sizeof(point) ; // error C3608: can''t apply sizeof to
a __gc array

Thanks in advance!!! : )

[==P ==]




这篇关于元素数量是一个数组的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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