[LC++]Size of structure pointer/array

Paul M Foster paulf at quillandmouse.com
Fri Aug 31 11:51:30 UTC 2001


On Thu, Aug 30, 2001 at 03:55:21PM +0200, Carlo Wood wrote:

> On Thu, Aug 30, 2001 at 12:46:23AM -0400, Paul M Foster wrote:

<snip>

> > The code generated by using a vector would be far more complex
> > than simply using an array. Harder to debug if incorrect, as well.
> >
> > That said, though, I do use vectors when I don't know how big an "array"
> > will get, and it's more natural to initialize it with a push_back().
> >
> > The main reasons I use C++ are to make things easier on myself as the
> > programmer, and to protect my code from me. ;-} That is, 1) type
> > checking is more rigid in C++; 2) classes allow for a simpler API in the
> > main program; 3) classes allow for more compartmented testing of
> > software components; and 4) classes (if properly designed), prevent me
> > and others from screwing around with the inside of a class object (that
> > is, the object is opaque, except for its API or methods).
> >
> > Paul
> 
> Of course I agree with you, and of course I'd use an array too in
> this case.  It's my opinion however that I think that C++ newbies should
> FIRST learn to use the STL correctly and THEN learn about arrays.
> I am sorry if my remark came accross as an attack towards your coding
> style - that was not my intention; my intention was to warn the learning
> newbie that this knowledge is dangerous to get used to too early ;).
> When I write to this list I address everyone, especially the unexperienced
> users.

Oh, I understood that your communication was aimed at the list in
general, not at me in particular. I'm not a C++ savant (obviously), but
I do occasionally run into C++ bigotry, where the most arcane C++
solutions are used to solve the simplest problems, simply because "it's
C++ and you have to do everything the C++ way." Argh.

I tend to think that C++ users should have a good grounding in C before
tackling C++, which would include knowing all about arrays before
working with vectors. (And I'm a hypocrite too, because I don't have
_full_ mastery of C, and I'm coding in C++. ;-)

BTW, thanks for the tips above.

You mentioned that the benefits of iostreams are only realized when
using them exclusively (as opposed to printf). I agree completely on
printing complex objects; printf just won't cut it for that. But in some
cases I've found it nearly impossible to correctly print, say, formatted
numbers, using iostreams (where it's very easy to do so with printf).
Maybe I just need to study it more.

Paul



More information about the tuxCPProgramming mailing list