home *** CD-ROM | disk | FTP | other *** search
/ NetNews Usenet Archive 1992 #27 / NN_1992_27.iso / spool / comp / lang / cplus / 16345 < prev    next >
Encoding:
Text File  |  1992-11-16  |  1.2 KB  |  64 lines

  1. Newsgroups: comp.lang.c++
  2. Path: sparky!uunet!mcsun!sunic!ericom!etxmtsb
  3. From: etxmtsb@solsta.ericsson.se (Mats Bengtsson  TX/DK )
  4. Subject: Re: how to initilize an array inside of a class??
  5. Message-ID: <etxmtsb.721913062@solsta>
  6. Sender: news@ericsson.se
  7. Nntp-Posting-Host: solsta.ericsson.se
  8. Organization: Ericsson
  9. References: <BxL3t2.FKG@ns1.nodak.edu> <1992Nov13.191618.5529@microsoft.com>
  10. Date: Mon, 16 Nov 1992 11:24:22 GMT
  11. Lines: 51
  12.  
  13. jimad@microsoft.com (Jim Adcock) writes:
  14.  
  15. .....
  16.  
  17. >#include <iostreams.h>
  18.  
  19. >typedef int* intptr;
  20.  
  21. >class IArray
  22. >{
  23. >public:
  24. >    int arr[8];
  25. >    void print() ;
  26. >    operator intptr() { return arr; }
  27. >};
  28.  
  29. >void IArray::print() 
  30. >{ for (int i=0; i<8; ++i) cout << arr[i] << ' '; cout << '\n'; }
  31.  
  32. >const IArray odds = {1, 3, 5, 7, 9, 11, 13, 15};
  33.  
  34. >class X
  35. >{
  36. >public:
  37. >    IArray i;
  38. >    void print() { i.print(); }
  39. >    X() : i(odds) {}
  40. >};
  41.  
  42. Why isn't is possible to write
  43.     X() : I({1,3,5,7,9,11,13,15}) {}
  44. I think that would be an obvious solution. The same syntax should also
  45. be suitable for other aggregates (that is, classes with no constructors,
  46. no private or protected members a.s.o.). 
  47.  
  48.  
  49. >main()
  50. >{
  51. >    X x;
  52. >    X y;
  53. >    x.print();
  54. >    x.i[1] = 9999;
  55. >    x.print();
  56. >    y.print();
  57.  
  58. >    return 0;
  59. >}
  60.  
  61.  
  62.   /Mats Bengtsson
  63.  
  64.