home *** CD-ROM | disk | FTP | other *** search
- Newsgroups: comp.lang.c++
- Path: sparky!uunet!gatech!darwin.sura.net!jvnc.net!newsserver.technet.sg!nuscc!argon!suresh
- From: suresh@argon.iss.nus.sg (Suresh Thennarangam - Research Scholar)
- Subject: Re: Newing a pointer to a pointer
- Message-ID: <1992Dec30.064540.16959@nuscc.nus.sg>
- Sender: usenet@nuscc.nus.sg
- Reply-To: suresh@iss.nus.sg (Suresh Thennarangam - Research Scholar)
- Organization: Institute of Systems Science, NUS, Singapore
- References: <1992Dec29.174843.20250@ncsu.edu>
- Date: Wed, 30 Dec 1992 06:45:40 GMT
- Lines: 42
-
- In article <1992Dec29.174843.20250@ncsu.edu> jlnance@eos.ncsu.edu (JAMES LEWIS NANCE) writes:
- >
- >I am attempting to learn C++. I have declared a class called list and class
- >called generic. In generic, lspace is declared as:
- >
- >list **lspace.
- >
- >Both g++ and cfront tell me that the line containing new in the following
- >constructor has a syntax error.
- >
- >generic::generic() {
- >this->lrow = 100;
- >this->lcol = 100;
- >this->lsize = 0;
- >this->lspace = new *list[lcol];
- >this->addrow();
- >printf("Constructing element\n");
- >}
- >Can someone tell me what I am doing wrong?
-
- There is a syntax error ... are you trying to allocate an array of list * ?
-
- This is the syntax you should use
-
- this->lspace = new list * [lrow] ;
-
- This will allocate lrow pointers to arrays of list ; no constructor is called yet.
-
- then you can allocate arrays of list like so
-
- for(i =0 i < lrow; i++) this->lspace[i] = new list[lcol];
-
- Hope that answers your question.
-
- ***************************************************************************
- * Suresh Thennarangam * EMail: suresh@iss.nus.sg(Internet) *
- * Research Scholar * ISSST@NUSVM.BITNET *
- * Institute Of Systems Science * Tel: (065) 772 2588. *
- * National University Of Singapore * Facs.: (065) 778 2571 *
- * Heng Mui Keng Terrace * Telex: ISSNUS RS 39988 *
- * Singapore 0511. * *
- ***************************************************************************
-