home *** CD-ROM | disk | FTP | other *** search
- Path: sparky!uunet!ogicse!news.u.washington.edu!ns1.nodak.edu!plains.NoDak.edu!cooper
- From: cooper@plains.NoDak.edu (Jeff Cooper)
- Newsgroups: comp.lang.c++
- Subject: how to initilize an array inside of a class??
- Message-ID: <BxL3t2.FKG@ns1.nodak.edu>
- Date: 12 Nov 92 03:46:14 GMT
- Article-I.D.: ns1.BxL3t2.FKG
- Sender: usenet@ns1.nodak.edu (News login)
- Organization: North Dakota Higher Education Computing Network
- Lines: 44
- Nntp-Posting-Host: plains.nodak.edu
-
- I have a bit of a problem that I can't really see an elegant solution
- for and I hope someone can point me in the right direction. I have
- a class that looks something like this:
-
- class Y : public X
- {
- public:
- int some_ints[3000];
- Y();
- ...
- };
-
- Now what I'd need to do is initilize the array 'some_ints' with some
- preset values...normally one would do it like:
-
- int some_ints[3000] = { 1, 6, 34, 3, ... ,0 };
-
- But my compiler complains about that, saying that I can't initialize
- class members there. The only other way I can think of doing it is
- to do something like:
-
- Y::Y()
- {
- some_ints[0] = 1;
- some_ints[1] = 6;
- ...
- some_ints[2999] = 0;
- }
-
- Is this my only other option?? If it is, it's not really all that bad
- as this code is being generated by another program, so I won't have to
- type in 3000 entries like that, but I was hoping for a more elegant
- solution...Would there be a performance hit doing it that way, I kinda
- think so as the first one is done at compile time, while the other is
- done at run-time, correct??
-
- Any Ideas?
-
-
- --
- "Life is pain Highness, anyone | Jeff Cooper
- who tells you different is | cooper@plains.nodak.edu
- selling something." | NeXTMail: cooper%midkemia@plains.nodak.edu
- - The Dread Pirate Roberts | (701) 298-0893
-