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

  1. Newsgroups: comp.lang.c++
  2. Path: sparky!uunet!pipex!warwick!dcs.warwick.ac.uk!cmchan
  3. From: cmchan@dcs.warwick.ac.uk (C M Chan)
  4. Subject: Simulate "Pointer to char" by an array
  5. Message-ID: <1992Dec30.172241.11378@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:22:41 GMT
  10. Lines: 37
  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 \
  18. delayed to be
  19. defined at run time?
  20.  
  21. For example,
  22.  
  23.  
  24.      class X {
  25.  
  26.      private:
  27.              char string[      ];    /* not define size of the array */
  28.                               ^^^^^^^^
  29.      public:
  30.              X(int);
  31.  
  32.              ...............
  33.      };
  34.  
  35.  
  36.      X::X(int size) {
  37.              string[size];          /*  define size of string array now  */
  38.              strcpy(string, "Hello");
  39.      }
  40.  
  41. Any pointer to this problem will be greatly appreciated.   Thanks in advance.
  42.  
  43.  
  44.  
  45. -- 
  46. C M CHAN         cmchan@dcs.warwick.ac.uk
  47.  
  48.  
  49.