Thread: classes

  1. #1
    Frustrated Programmer :( phantom's Avatar
    Join Date
    Sep 2001
    Posts
    163

    classes

    The following code works correctly, the questions is simply -> is there a better way of doing this? I have tried a 'for' loop but it tells me that it can't initialise 'job'.

    heading job[12]=
    {
    heading(500.0f, 150.0f, game_stats[0], 1.0f, 0.4f),
    heading(500.0f, 170.0f, game_stats[1], 1.0f, 0.4f),
    heading(500.0f, 190.0f, game_stats[2], 1.0f, 0.4f),
    heading(500.0f, 210.0f, game_stats[3], 1.0f, 0.4f),
    heading(500.0f, 230.0f, game_stats[4], 1.0f, 0.4f),
    heading(500.0f, 250.0f, game_stats[5], 1.0f, 0.4f),
    heading(500.0f, 270.0f, game_stats[6], 1.0f, 0.4f),
    heading(500.0f, 290.0f, game_stats[7], 1.0f, 0.4f),
    heading(500.0f, 310.0f, game_stats[8], 1.0f, 0.4f),
    heading(500.0f, 330.0f, game_stats[9], 1.0f, 0.4f),
    heading(500.0f, 350.0f, game_stats[10], 1.0f, 0.4f),
    heading(500.0f, 370.0f, game_stats[11], 1.0f, 0.4f)
    };
    My site to register for all my other websites!
    'Clifton Bazaar'

  2. #2
    ¡Amo fútbol!
    Join Date
    Dec 2001
    Posts
    2,138
    Although that seems like more work to type, I think that it would be better performance-wise than using a loop to assign the values. Correct me if I am wrong.

  3. #3
    A correctly written FOR loop can be more efficient than what you have.

    You need to create the job[] array first and then use a for loop to initiliaze it's values. Not create the job[] array and initialize it at the same time, instead use the for loop to assign the values of the array after it's been created. Within the scope of the FOR loop create variables to hold the fxn argument values this way you can inherit and increment the settings without entering in specific data.
    My Avatar says: "Stay in School"

    Rocco is the Boy!
    "SHUT YOUR LIPS..."

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Can you Initialize all classes once with New?
    By peacerosetx in forum C++ Programming
    Replies: 12
    Last Post: 07-02-2008, 10:47 AM
  2. Multiple Inheritance - Size of Classes?
    By Zeusbwr in forum C++ Programming
    Replies: 10
    Last Post: 11-26-2004, 09:04 AM
  3. im extreamly new help
    By rigo305 in forum C++ Programming
    Replies: 27
    Last Post: 04-23-2004, 11:22 PM
  4. Prime Number Generator... Help !?!!
    By Halo in forum C++ Programming
    Replies: 9
    Last Post: 10-20-2003, 07:26 PM
  5. include question
    By Wanted420 in forum C++ Programming
    Replies: 8
    Last Post: 10-17-2003, 03:49 AM