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