🚀 go-pugleaf

RetroBBS NetNews Server

Inspired by RockSolid Light RIP Retro Guy

Article View: comp.std.c++
Article #1177

Array in class

#1177
From: C M Chan
Date: Wed, 30 Dec 1992 17:18
36 lines
1210 bytes
Hi out there,

I am sorry if this is faq for this newsgroup.   Here is my question:

How can I simulate "pointer to char" by an array in a class whose size will be delayed to be
defined at run time?

For example,


          class X {

          private:
                   char string[      ];    /* not define size of the array */
                              ^^^^^^^^       
          public:
                   X(int);

                   ...............
          };


          X::X(int size) {
                 string[size];          /*  define size of string array now  */
                 strcpy(string, "Hello");
          }

Any pointer to this problem will be greatly appreciated.   Thanks in advance.





-- 
C M CHAN         cmchan@dcs.warwick.ac.uk
Technical Details
Message-ID: <1992Dec30.171846.11230@dcs.warwick.ac.uk>
Path: arc1-ca.pugleaf.net!sparky!uunet!pipex!warwick!dcs.warwick.ac.uk!cmchan

Show Full Headers
Complete Article Headers
Newsgroups: comp.std.c++
Path: arc1-ca.pugleaf.net!sparky!uunet!pipex!warwick!dcs.warwick.ac.uk!cmchan
From: cmchan@dcs.warwick.ac.uk (C M Chan)
Subject: Array in class
Message-ID: <1992Dec30.171846.11230@dcs.warwick.ac.uk>
Sender: news@dcs.warwick.ac.uk (Network News)
Nntp-Posting-Host: stone
Organization: Department of Computer Science, Warwick University, England
Date: Wed, 30 Dec 1992 17:18:46 GMT
Lines: 38