home *** CD-ROM | disk | FTP | other *** search
/ NetNews Usenet Archive 1992 #26 / NN_1992_26.iso / spool / comp / lang / cplus / 16217 < prev    next >
Encoding:
Text File  |  1992-11-13  |  1.8 KB  |  39 lines

  1. Newsgroups: comp.lang.c++
  2. Path: sparky!uunet!zaphod.mps.ohio-state.edu!wupost!spool.mu.edu!umn.edu!deci.cs.umn.edu!hansen
  3. From: hansen@deci.cs.umn.edu (David M. Hansen)
  4. Subject: Re: 'new' syntax?
  5. Message-ID: <1992Nov13.143654.28449@news2.cis.umn.edu>
  6. Sender: news@news2.cis.umn.edu (Usenet News Administration)
  7. Nntp-Posting-Host: deci.cs.umn.edu
  8. Organization: University of Minnesota
  9. References: <1992Nov13.095152.26819@rs6000.bham.ac.uk> <1992Nov13.124612.1@vax1.bham.ac.uk>
  10. Date: Fri, 13 Nov 1992 14:36:54 GMT
  11. Lines: 26
  12.  
  13. In article <1992Nov13.124612.1@vax1.bham.ac.uk>, mccauleyba@vax1.bham.ac.uk (Brian McCauley) writes:
  14. |> In article <1992Nov13.095152.26819@rs6000.bham.ac.uk>, pickerig@eee.bham.ac.uk (Mr. G. Pickering) writes:
  15. |> > I want to create an array of 'size' long**, is the correct syntax:
  16. |> > 
  17. |> >   long*** new_blocks = new (long**[size]);
  18. |> > 
  19. |> > I am having memory corruption problems and suspect this is not doing
  20. |> > what I really want.
  21. |> I have trouble with the new operator myself I normally give up trying to
  22. |> understand the syntax and use a local typedef.
  23. |> {
  24. |>   typedef long **longPtrPtr;
  25. |>   longPtrPtr *new_blocks = new longPtrPtr[size];
  26. |> }
  27. |> Possibly not the most elegant solution but at least it works.
  28.  
  29. Hear, hear!  The trouble, I think, is not with the new operator, but with 
  30. the C syntax of declaring variables, which was once descibed to me as "an
  31. experiment that failed."  I almost always try to build complex types
  32. from simpler ones using typedef.  This is nice because the new type names
  33. are reusable, and are generally easier to read and understand than 'raw'
  34. declarations (IMHO).  The only major problem that I see with typedef is that
  35. it does not handle arrays very well (or is it vice versa...?).  If you
  36. want a typedef'ed array, it is best to enclose the array in a struct.
  37.  
  38.                     -=Dave
  39.