473,378 Members | 1,395 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,378 software developers and data experts.

Number of elements is an array

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 ==]
Nov 17 '05 #1
11 1456
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...
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 ==]

Nov 17 '05 #2
point->Length

"Peter Oliphant" <po*******@RoundTripInc.com> wrote in message
news:eQ*************@TK2MSFTNGP10.phx.gbl...
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 ==]

Nov 17 '05 #3
> #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" <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...
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 ==]


Nov 17 '05 #4
Hi James,

Unfortunately points->Length doesn't work, but instead generates the error:

C2039: 'Length' is not a member of 'System::Drawing::Point'.

And I've tried 'length', 'size', and 'Size' as well, with no luck.

There HAS to be way to get the number of elements in a Point[] array, but
what is it?

[==P==]

"James Park" <so*****@hotmail.com> wrote in message
news:Oi**************@TK2MSFTNGP09.phx.gbl...
point->Length

"Peter Oliphant" <po*******@RoundTripInc.com> wrote in message
news:eQ*************@TK2MSFTNGP10.phx.gbl...
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 ==]


Nov 17 '05 #5
My apologies, I was using it wrong. point->Length DOES work. Thanks! : )

[==P=]]

"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...
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 ==]


Nov 17 '05 #6
My apologies, I was using it wrong. point->Length DOES work. Thanks! : )

[==P=]

"Peter Oliphant" <po*******@RoundTripInc.com> wrote in message
news:%2****************@TK2MSFTNGP12.phx.gbl...
Hi James,

Unfortunately points->Length doesn't work, but instead generates the
error:

C2039: 'Length' is not a member of 'System::Drawing::Point'.

And I've tried 'length', 'size', and 'Size' as well, with no luck.

There HAS to be way to get the number of elements in a Point[] array, but
what is it?

[==P==]

"James Park" <so*****@hotmail.com> wrote in message
news:Oi**************@TK2MSFTNGP09.phx.gbl...
point->Length

"Peter Oliphant" <po*******@RoundTripInc.com> wrote in message
news:eQ*************@TK2MSFTNGP10.phx.gbl...
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 ==]



Nov 17 '05 #7
Ok, got another question. How do I return a Point[] (pointer) from a method?
The following won't work:

Point[] Get_Points() { return m_Points ; } // error: Point[] is not a valid
syntax here

where m_Points is defined by:

Point m_Points[] ;

I CAN return a pointer to the first element of the list, but I'm guessing
this doesn't retain the array info (such as 'Length'....hehe). That is, I
CAN do the following:

Point* Get_Points() { return &(m_Points[0]) ; }

Is there a way to return a pointer to an array of Point's? Will the above do
the trick and preserve its interpretation of the return value as a pointer
to an array, not just a single element (which I doubt, but it might know
from context)?

Thanks (again) in advance! : )

[==P==]

"James Park" <so*****@hotmail.com> wrote in message
news:Oi**************@TK2MSFTNGP09.phx.gbl...
point->Length

"Peter Oliphant" <po*******@RoundTripInc.com> wrote in message
news:eQ*************@TK2MSFTNGP10.phx.gbl...
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 ==]


Nov 17 '05 #8
Peter Oliphant wrote:
Ok, got another question. How do I return a Point[] (pointer) from a
method? The following won't work:

Point[] Get_Points() { return m_Points ; } // error: Point[] is not a
valid syntax here


Point Get_Points() []
{ return m_Points ; }

Geee, *why* oh why did they choose to keep this awfull K&R syntax ;-(

Arnaud
MVP - VC
Nov 17 '05 #9
> Point Get_Points() []
{ return m_Points ; }
I never in a million years would have tried that syntax...but it definitely
works...Thanks!!! : )

[==P==]

"Arnaud Debaene" <ad******@club-internet.fr> wrote in message
news:ux****************@TK2MSFTNGP09.phx.gbl... Peter Oliphant wrote:
Ok, got another question. How do I return a Point[] (pointer) from a
method? The following won't work:

Point[] Get_Points() { return m_Points ; } // error: Point[] is not a
valid syntax here


Point Get_Points() []
{ return m_Points ; }

Geee, *why* oh why did they choose to keep this awfull K&R syntax ;-(

Arnaud
MVP - VC

Nov 17 '05 #10
Sorry Peter, didn't understand your requirement. Length would be the way to
go in this case. I thought you were using a generic example.

Tom

"Peter Oliphant" <po*******@RoundTripInc.com> wrote in message
news:ez**************@tk2msftngp13.phx.gbl...
#define POINT_ARRAY_SZ 3

Point point[] = new Point[POINT_ARRAY_SZ];

Then you could use it anywhere you want.


Hi Tom,

Nov 17 '05 #11
Peter Oliphant wrote:
Point Get_Points() []
{ return m_Points ; }


I never in a million years would have tried that syntax...


Well, RTFM ;-)
http://msdn.microsoft.com/library/de...Spec_4_5_2.asp

Arnaud
MVP - VC


Nov 17 '05 #12

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

7
by: peter | last post by:
Hello, for a C++ delete: class Test{}; Test * A = new Test; delete A; We don't use delete A; How can C++ compiler can tell there are 50 destructor to deallocate?
6
by: Herrcho | last post by:
in K&R Chapter 6.3 it mentions two methods to calculate NKEYS. and points out the first one which is to terminate the list of initializers with a null pointer, then loop along keytab until the...
18
by: Vasilis Serghi | last post by:
Presently I define the number of lines to be expected in a file when defining the array size and the initialisation of this array. This works fine for now, but i'm sure that in the future this...
21
by: Jaspreet | last post by:
I was working on some database application and had this small task of getting the second highes marks in a class. I was able to do that using subqueries. Just thinking what is a good way of...
2
by: mikeoley | last post by:
Ok I have a Javascript slideshow working. Every image is linked to a another page in the site. Problem is...The link wont refresh to the next link once the second images rollovers in the slideshow....
18
by: Andrew | last post by:
Hi, I have a scenario in which both the source and format string for a sscanf() call is selected *at runtime*. The number of format conversions/substitutions is known as well as the maximum...
17
by: rhitz1218 | last post by:
Hi, I'm trying to create a function that will sort a number's digits from highest to lowest. For example 1000 - will become 0001 or 1234 to 4321
9
by: Grey Alien | last post by:
If I have a struct declared as : struct A { double x ; char name; struct Other other ; void * ptr ; };
11
by: C C++ C++ | last post by:
Hi all, got this interview question please respond. How can you quickly find the number of elements stored in a a) static array b) dynamic array ? Rgrds MA
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome former...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.