home *** CD-ROM | disk | FTP | other *** search
/ NetNews Usenet Archive 1992 #26 / NN_1992_26.iso / spool / comp / lang / cplus / 16137 < prev    next >
Encoding:
Text File  |  1992-11-11  |  1.7 KB  |  57 lines

  1. Path: sparky!uunet!ogicse!news.u.washington.edu!ns1.nodak.edu!plains.NoDak.edu!cooper
  2. From: cooper@plains.NoDak.edu (Jeff Cooper)
  3. Newsgroups: comp.lang.c++
  4. Subject: how to initilize an array inside of a class??
  5. Message-ID: <BxL3t2.FKG@ns1.nodak.edu>
  6. Date: 12 Nov 92 03:46:14 GMT
  7. Article-I.D.: ns1.BxL3t2.FKG
  8. Sender: usenet@ns1.nodak.edu (News login)
  9. Organization: North Dakota Higher Education Computing Network
  10. Lines: 44
  11. Nntp-Posting-Host: plains.nodak.edu
  12.  
  13. I have a bit of a problem that I can't really see an elegant solution
  14. for and I hope someone can point me in the right direction.  I have
  15. a class that looks something like this:
  16.  
  17. class Y : public X
  18. {
  19.     public:
  20.         int some_ints[3000];
  21.         Y();
  22.         ...
  23. };
  24.  
  25. Now what I'd need to do is initilize the array 'some_ints' with some
  26. preset values...normally one would do it like:
  27.  
  28. int some_ints[3000] = { 1, 6, 34, 3, ... ,0 };
  29.  
  30. But my compiler complains about that, saying that I can't initialize
  31. class members there.  The only other way I can think of doing it is
  32. to do something like:
  33.  
  34. Y::Y()
  35. {
  36.     some_ints[0] = 1;
  37.     some_ints[1] = 6;
  38.     ...
  39.     some_ints[2999] = 0;
  40. }
  41.  
  42. Is this my only other option??  If it is, it's not really all that bad
  43. as this code is being generated by another program, so I won't have to
  44. type in 3000 entries like that, but I was hoping for a more elegant
  45. solution...Would there be a performance hit doing it that way, I kinda
  46. think so as the first one is done at compile time, while the other is
  47. done at run-time, correct??
  48.  
  49. Any Ideas?
  50.  
  51.  
  52. -- 
  53. "Life is pain Highness, anyone    |  Jeff Cooper
  54. who tells you different is    |  cooper@plains.nodak.edu
  55. selling something."        |  NeXTMail: cooper%midkemia@plains.nodak.edu
  56.     - The Dread Pirate Roberts    |  (701) 298-0893
  57.