Archived

This topic is now archived and is closed to further replies.

Defining Arrays in Constructors?

This topic is 5765 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

Recommended Posts

How can I define an array inside a constructor? Say i have:  struct STRUCTURE { int var[10]; STRUCTURE() { // how to define here? } };  I tried using a FOR loop to do it, but i didn''t seem to work. What else can I do? Thanks! *====================* http://www.syntasoft.com *=======================*

Share on other sites
The for-loop is the only thing that would make sense (for different values). If you all want identical values, such as 0, you might use memset.

Share on other sites
Hmm... for some reason when I use the FOR loop it doesn't work. I have no idea why. I haven't tried memset yet though. I do something like this:

typedef struct STRUCTURE{ int iLookForPass[MAX_PLAY_ADJUSTMENTS]; STRUCTURE() { for(int a=0; a iLookForPass[ a ] = UNDEFINED; } }};

[edited by - Gf11speed on February 1, 2003 3:22:58 AM]

Share on other sites
what doesn''t work in it? how is it broken?

Share on other sites
I got it... the problem was not in the code, but the fact that I kept loading the previous struct from disk where it wasn''t initialized properly. Oops!

Thanks for the help guys...

1. 1
2. 2
Rutin
19
3. 3
4. 4
5. 5

• 9
• 9
• 9
• 14
• 12
• Forum Statistics

• Total Topics
633295
• Total Posts
3011245
• Who's Online (See full list)

There are no registered users currently online

×