Re: trouble creating array of objects

From: Greg Comeau (comeau_at_panix.com)
Date: 12/02/03


Date: 2 Dec 2003 15:01:08 -0500

In article <1070368078.78862@news.minx.net.uk>,
Jumbo <pcrcutitout1000011@uko2.co.uk> wrote:
>Vectors are not a replacement for arrays.
>1 reason he might not want to use vectors is perhaps because he isn't ready
>to start using vectors.
>Another reason is perhaps because he doesn't understand templates therefore
>he doesn't understand how the vector class works..
>Another reason might be the overheads incurred.
>Or perhaps he is simply learning about Arrays.
>There are lots of reasons not to use vectors.
>
>And the major reason here is that you should not be using advanced templated
>classes if you don't even know how to create a 2d array dynamically.
>
>I am getting used to seeing this reply to array questions and your lack
>understanding of the difference between arrays and vectors but it fails to
>surprise me anymore.
>
>So I shun your advice and tell the chap to continue learning about arrays
>until he is ready to start using the standard template library.

It's so that there may be reasons for one or the other.
However, there being a newbie isn't necessarily one of them.
Yes, there is a learning curve to telling newbie's to
#include this or and and also to use <>'s with a type.
However, using the built-in array has learning curve
costs associated with it too. So they both have many
cons.

That said, I prefer newbie to learn the lib version first
because they are more first class citizens in many cases
than the builtin types are. This brings along with it
that issues like providing type safety and being able
to sidestep common errors can be postpone, and also that
folks can get to the conceptual issues and actually producing
something, rather than fighting syntax and such.

So in short, telling somebody to use std::vector<int> is
hardly any more "advanced" than telling them to use int X[??],
and has been shown that folks can immediately be able to begin
using the basics of the C++ Standard Library. IOWs, they
can be immediately ready to use the parts of it which make
sense for a beginner to use.

-- 
Greg Comeau/4.3.3:Full C++03 core language + more Windows backends
Comeau C/C++ ONLINE ==>     http://www.comeaucomputing.com/tryitout
World Class Compilers:  Breathtaking C++, Amazing C99, Fabulous C90.
Comeau C/C++ with Dinkumware's Libraries... Have you tried it?


Relevant Pages

  • Re: trouble creating array of objects
    ... >>1 reason he might not want to use vectors is perhaps because he isn't ... >>Or perhaps he is simply learning about Arrays. ... A programmer should at least know and understand templates before they use ...
    (alt.comp.lang.learn.c-cpp)
  • Re: [PATCH 1/2] avoid OPEN_MAX in SCM_MAX_FD
    ... In git, I used PATH_MAX, and the reason ... I want a constant for arrays ... to some paper standard". ... realize that modern distributions don't put the kernel headers in their ...
    (Linux-Kernel)
  • Re: trouble creating array of objects
    ... > about dynamically multidimensinoal arrays is described. ... it's an excellent learning excercise. ... This is called the C++ standard template library and it is an addition to ... >> Another reason might be the overheads incurred. ...
    (alt.comp.lang.learn.c-cpp)
  • Re: about sprintf function
    ... > will write to some memory locations beyond 'str' and corrupt them. ... that is *not* the reason the result is different. ... even if both str and append contain 2 character strings. ... You need 13 byte long arrays if you want to fit "some__string" ...
    (comp.lang.c)
  • Re: How do I pass a complex data array into a C dll
    ... using some other libraries to improve ... on Labviews functionality).I think it's a bit strange Labview ... LabVIEW to add this type as well to the Call Library Node. ... switch the real and imaginair part of treat complex arrays as two ...
    (comp.lang.labview)