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

  1. Newsgroups: comp.std.c++
  2. Path: sparky!uunet!pipex!warwick!dcs.warwick.ac.uk!cmchan
  3. From: cmchan@dcs.warwick.ac.uk (C M Chan)
  4. Subject: Array in class
  5. Message-ID: <1992Dec30.171846.11230@dcs.warwick.ac.uk>
  6. Sender: news@dcs.warwick.ac.uk (Network News)
  7. Nntp-Posting-Host: stone
  8. Organization: Department of Computer Science, Warwick University, England
  9. Date: Wed, 30 Dec 1992 17:18:46 GMT
  10. Lines: 38
  11.  
  12.  
  13. Hi out there,
  14.  
  15. I am sorry if this is faq for this newsgroup.   Here is my question:
  16.  
  17. How can I simulate "pointer to char" by an array in a class whose size will be delayed to be
  18. defined at run time?
  19.  
  20. For example,
  21.  
  22.  
  23.           class X {
  24.  
  25.           private:
  26.                    char string[      ];    /* not define size of the array */
  27.                               ^^^^^^^^       
  28.           public:
  29.                    X(int);
  30.  
  31.                    ...............
  32.           };
  33.  
  34.  
  35.           X::X(int size) {
  36.                  string[size];          /*  define size of string array now  */
  37.                  strcpy(string, "Hello");
  38.           }
  39.  
  40. Any pointer to this problem will be greatly appreciated.   Thanks in advance.
  41.  
  42.  
  43.  
  44.  
  45.  
  46. -- 
  47. C M CHAN         cmchan@dcs.warwick.ac.uk
  48.  
  49.  
  50.