Re: Question about arrays in objects

From: Leor Zolman (leor_at_bdsoft.com)
Date: 01/17/04


Date: Sat, 17 Jan 2004 03:38:52 GMT

On Sat, 17 Jan 2004 03:11:45 GMT, Joec <joec@annuna.com> wrote:

>Wow it is pretty complex. Mainly I want a static array of objects as a
>data member. I am no expert at C++ but I am trying to expand the
>knowlege I have from several books. I am trying to apply what I have
>learned. The more I study the more I realize how much many books leave
>out and hard it is in choosing books.

One of the problems with talking about C++ is that certain terms,
"static" being arguably the worst offender, are way too "overloaded".
As a keyword, it has four different meanings in declarations based on
context. And then there's when it is used "conversationally" as an
adjective to describe storage duration. So what you're thinking when
you use the phrase "static array of objects" above may not be the same
as what pops into the mind of the person reading it. This is just a
C++ occupational hazard... ;-)

Case in point: let's take your phrase above, "static array of
objects". If you're literally meaning a data member declared with the
storage class specifier "static", then that means there's one copy of
that array shared among all the instances of the class you ever
create. Is that what you mean?

If you mean "fixed size", a la the "enum"-based example I gave you,
then there's no use of the word "static" that would generally apply to
it! For a class x defined like this:
        class x {
                enum { size = 100};
                int array[size];
        };

An instance at file (global) scope like this:

x x1;

would be said to have "static storage", but within a function like
this:

        int foo()
        {
                x x2;
        }

it would have "automatic" storage. And if you created an instance
like this:
        x *xp = new x;

then it would have "dynamic" storage!

Just some food for thought...anyway, if you haven't added Scott
Meyers' Effective C++ to your book collection yet, run (don't walk) to
your bookstore or favorite online bookseller and do so!
        -leor

>
>Thanks for the reply and the pointers.

Leor Zolman
BD Software
leor@bdsoft.com
www.bdsoft.com -- On-Site Training in C/C++, Java, Perl & Unix
C++ users: Download BD Software's free STL Error Message
           Decryptor at www.bdsoft.com/tools/stlfilt.html



Relevant Pages

  • Re: To Pack Away ,Or Not
    ... fifty built models, 600+ books and magazines. ... All the same sized boxes allowed for best storage of unbuilt kits. ...
    (rec.models.scale)
  • Re: To Pack Away ,Or Not
    ... fifty built models, 600+ books and magazines. ... I found one source for all of the storage and move: ... heavy yet they are big enough to hold all but the largest kits. ... same sized boxes allowed for best storage of unbuilt kits. ...
    (rec.models.scale)
  • Re: Stepping Up to DSLR - Canon 350D
    ... it be better for macro stuff than the compacts built in macro mode? ... will I have to buy some serious storage? ... average day out etc. Do I have to up the anti with a DSLR. ... Are there any books that you would recommend to get me up to speed? ...
    (rec.photo.digital.slr-systems)
  • Re: (nbc) where/how do you store your music???
    ... This type of storage ultimately takes up much less room that "book case" or "revolving rack" storage and the tops can double as table/work space or stereo equipment storage. ... I guess I'm showing my age, but if we were talking about books, would people consider "ripping off the covers" to fit more books on their shelves? ...
    (rec.music.artists.springsteen)
  • Re: Classic Fireworks Books on Limewire
    ... I'm starting to recall that old phrase "No Good Deed goes ... Classic Fireworks Books on Limewire ... it's only a complaint if my files were distributed thus. ... sider regarding e-book materials of this sort: ...
    (rec.pyrotechnics)