home *** CD-ROM | disk | FTP | other *** search
- Nntp-Posting-Host: solva.ifi.uio.no
- Newsgroups: comp.lang.c++
- Path: sparky!uunet!psinntp!sunic!aun.uninett.no!nuug!ifi.uio.no!nntp.ifi.uio.no!jar
- From: jar@solva.ifi.uio.no (Jo Are Rosland)
- Subject: Re: using new
- In-Reply-To: ae2@cunixa.cc.columbia.edu's message of Fri, 8 Jan 1993 17:19:50 GMT
- Message-ID: <JAR.93Jan10164850@solva.ifi.uio.no>
- X-Md4-Signature: f92980b69468f75c25c2139d72153b3e
- Sender: jar@ifi.uio.no (Jo Are Rosland)
- Organization: Dept. of Informatics, University of Oslo, Norway
- References: <1993Jan8.171950.22884@news.columbia.edu>
- Date: Sun, 10 Jan 1993 15:48:50 GMT
- Lines: 31
- Originator: jar@solva.ifi.uio.no
-
- In article <1993Jan8.171950.22884@news.columbia.edu> ae2@cunixa.cc.columbia.edu (Amiran Eliashvili) writes:
- I am in the process of porting a C program into C++ and
- learning a lot about C++. I am trying to find an equivalent C++
- construct for the following malloc command:
-
- ptr = (TypeCast *) malloc( LENGTH(n));
-
- where Length(n) is a macro that will return the n times of the
- desired object size. I have tried the following statement using new
- but for no avail:
-
- ptr = (TypeCast *) new char(LENGTH(n));
-
- This is really a question of the kind you'd find answered in any C++
- tutorial book. Your C++ should probably look like
-
- ptr = new TypeCast[n];
-
- which means "allocate enough space for an array of n elements of type
- TypeCast, then return a pointer to it of type TypeCast*".
-
- The corresponding free() statement should look like
-
- delete [] ptr;
-
- where the [] are necessary since you've allocated an array in the
- first place.
-
- --
- Jo Are Rosland
- jar@ifi.uio.no
-