#define POINT_ARRAY_SZ 3
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 said:
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 said:
Say I have a line in my code something like the following (NOTE: Point is
__value class System:
rawing:
oint):
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 ==]