home *** CD-ROM | disk | FTP | other *** search
- Newsgroups: comp.lang.c++
- Path: sparky!uunet!mcsun!sunic!ericom!etxmtsb
- From: etxmtsb@solsta.ericsson.se (Mats Bengtsson TX/DK )
- Subject: Re: how to initilize an array inside of a class??
- Message-ID: <etxmtsb.721913062@solsta>
- Sender: news@ericsson.se
- Nntp-Posting-Host: solsta.ericsson.se
- Organization: Ericsson
- References: <BxL3t2.FKG@ns1.nodak.edu> <1992Nov13.191618.5529@microsoft.com>
- Date: Mon, 16 Nov 1992 11:24:22 GMT
- Lines: 51
-
- jimad@microsoft.com (Jim Adcock) writes:
-
- .....
-
- >#include <iostreams.h>
-
- >typedef int* intptr;
-
- >class IArray
- >{
- >public:
- > int arr[8];
- > void print() ;
- > operator intptr() { return arr; }
- >};
-
- >void IArray::print()
- >{ for (int i=0; i<8; ++i) cout << arr[i] << ' '; cout << '\n'; }
-
- >const IArray odds = {1, 3, 5, 7, 9, 11, 13, 15};
-
- >class X
- >{
- >public:
- > IArray i;
- > void print() { i.print(); }
- > X() : i(odds) {}
- >};
-
- Why isn't is possible to write
- X() : I({1,3,5,7,9,11,13,15}) {}
- I think that would be an obvious solution. The same syntax should also
- be suitable for other aggregates (that is, classes with no constructors,
- no private or protected members a.s.o.).
-
-
- >main()
- >{
- > X x;
- > X y;
- > x.print();
- > x.i[1] = 9999;
- > x.print();
- > y.print();
-
- > return 0;
- >}
-
-
- /Mats Bengtsson
-
-