home *** CD-ROM | disk | FTP | other *** search
/ NetNews Usenet Archive 1992 #31 / NN_1992_31.iso / spool / comp / lang / cplus / 18533 < prev    next >
Encoding:
Text File  |  1992-12-30  |  2.0 KB  |  55 lines

  1. Newsgroups: comp.lang.c++
  2. Path: sparky!uunet!gatech!darwin.sura.net!jvnc.net!newsserver.technet.sg!nuscc!argon!suresh
  3. From: suresh@argon.iss.nus.sg (Suresh Thennarangam - Research Scholar)
  4. Subject: Re: Newing a pointer to a pointer
  5. Message-ID: <1992Dec30.064540.16959@nuscc.nus.sg>
  6. Sender: usenet@nuscc.nus.sg
  7. Reply-To: suresh@iss.nus.sg (Suresh Thennarangam - Research Scholar)
  8. Organization: Institute of Systems Science, NUS, Singapore
  9. References: <1992Dec29.174843.20250@ncsu.edu>
  10. Date: Wed, 30 Dec 1992 06:45:40 GMT
  11. Lines: 42
  12.  
  13. In article <1992Dec29.174843.20250@ncsu.edu> jlnance@eos.ncsu.edu (JAMES LEWIS NANCE) writes:
  14. >
  15. >I am attempting to learn C++.  I have declared a class called list and class
  16. >called generic.  In generic, lspace is declared as:
  17. >
  18. >list **lspace.
  19. >
  20. >Both g++ and cfront tell me that the line containing new in the following 
  21. >constructor has a syntax error.
  22. >
  23. >generic::generic() {
  24. >this->lrow   = 100;
  25. >this->lcol   = 100;
  26. >this->lsize  = 0;
  27. >this->lspace = new *list[lcol];
  28. >this->addrow();
  29. >printf("Constructing element\n");
  30. >}
  31. >Can someone tell me what I am doing wrong?
  32.  
  33. There is a syntax error ... are you trying to allocate an array of list * ?
  34.  
  35. This is the syntax you should use 
  36.  
  37. this->lspace = new list * [lrow] ;
  38.  
  39. This will allocate lrow pointers to arrays of list ; no constructor is called yet.
  40.  
  41. then you can allocate arrays of list like so
  42.  
  43. for(i =0 i < lrow; i++) this->lspace[i] = new list[lcol]; 
  44.  
  45. Hope that answers your question.
  46.  
  47. ***************************************************************************
  48. * Suresh Thennarangam               *  EMail: suresh@iss.nus.sg(Internet) *
  49. * Research Scholar                  *         ISSST@NUSVM.BITNET          *
  50. * Institute Of Systems Science      *  Tel:  (065) 772 2588.              *
  51. * National University Of Singapore  *  Facs.: (065) 778 2571              *
  52. * Heng Mui Keng Terrace             *  Telex: ISSNUS RS 39988             *
  53. * Singapore 0511.                   *                                     *
  54. ***************************************************************************
  55.