C++ - How do you declare an array of static structures?

Discussion in 'Game Development General Discussion' started by Trenton_net, Aug 17, 2010.

  1. Trenton_net

    Trenton_net AKA SUPERCOM32

    Joined:
    Apr 13, 2007
    Messages:
    2,378
    Likes Received:
    58
    Hey Everyone,

    Lets say you have an array of static structures, in which each structure element contains something like "Name", "Age", "Money". How would you declare and populate your static array of type struct?
     
  2. Calpis

    Calpis Champion of the Forum

    Joined:
    Mar 13, 2004
    Messages:
    5,906
    Likes Received:
    21
    #include "stdio.h"


    struct column {
    char *name;
    int age;
    int money;
    };

    const struct column table[] = {

    /* rows */
    {"bob",50,200},
    {"joe",30,50}

    };


    int main()
    {

    printf("%s %d %d", table[0].name, table[0].age, table[0].money);

    return 0;
    }

    if you mean you want hash/dictionary indexing, you'll have to create a special object for that
     
    Last edited: Aug 17, 2010
  3. Trenton_net

    Trenton_net AKA SUPERCOM32

    Joined:
    Apr 13, 2007
    Messages:
    2,378
    Likes Received:
    58
    Your explanation is simple, easy to understand, and straight to the point. I like it!

    Thanks!
     
sonicdude10
Draft saved Draft deleted
Insert every image as a...
  1.  0%

Share This Page