Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > C++ > do arrays hold pointers or the actual objects

Reply
Thread Tools

do arrays hold pointers or the actual objects

 
 
don
Guest
Posts: n/a
 
      02-08-2004
My question is, do C++ array of objects hold the objects or just the
pointers to the objects..... I know Java arrays only hold pointers to
objects, but I seem to remember that C++ arrays hold the actual object.....
please set me straight......


 
Reply With Quote
 
 
 
 
Jonathan Turkanis
Guest
Posts: n/a
 
      02-08-2004
"don" <(E-Mail Removed)> wrote in message
news:c047tv$ilo$(E-Mail Removed)...
> My question is, do C++ array of objects hold the objects or just

the
> pointers to the objects..... I know Java arrays only hold pointers

to
> objects, but I seem to remember that C++ arrays hold the actual

object.....
> please set me straight......
>


C++ arrays hold objects; the notion of object, however, is broad
enough to include pointers. If you have a class T, you can declare an
array of T's like

T a[N]

or an array of pointers to T like so

T* a[N]

Jonathan


 
Reply With Quote
 
 
 
 
Mike Wahler
Guest
Posts: n/a
 
      02-08-2004

"don" <(E-Mail Removed)> wrote in message
news:c047tv$ilo$(E-Mail Removed)...
> My question is, do C++ array of objects hold the objects


Yes.

> or just the
> pointers to the objects.....


No. However, objects stored in an array can be of pointer type.

> I know Java arrays only hold pointers to
> objects,


C++ is not Java. Despite their 'similarities', imo it's a
mistake to try to directly 'translate' programming constructs
and concepts from one language to the other. That way lies
madness....

>but I seem to remember that C++ arrays hold the actual object.....
> please set me straight......


Please read a C++ book.
http://www.accu.org/bookreviews/publ...nner_s_c__.htm

int arr1[10]; /* array of ten type 'int' objects */

int *arr2[10]; /* array of ten type 'pointer to int' objects */


Finally, note that in C++, imo one should generally prefer a container
(e.g. std::vector) over an array.

-Mike


 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
pointers, pointers, pointers... cerr C Programming 12 04-07-2011 11:17 PM
casting pointers/arrays to multidimensional arrays Francesco C++ 2 11-06-2009 09:04 AM
Multidimensional arrays and arrays of arrays Philipp Java 21 01-20-2009 08:33 AM
Learning pointers and arrays of pointers With Files ketema@gmail.com C Programming 1 03-28-2005 03:51 AM
Arrays and Pointers to Arrays kelvSYC C Programming 2 09-26-2003 06:52 AM



Advertisments