Thread: quick dumb question from a newbie (initializing arrays)

  1. #1
    Registered User
    Join Date
    Nov 2010
    Posts
    2

    quick dumb question from a newbie (initializing arrays)

    i want to manually initialize an array where each element of the array has 4 data fields.

    class sudo{
    int num;
    int row;
    int column;
    int box;
    };

    int main(){

    example: sudo board[9][9] = ??

    what is the syntax for initializing each element? I was thinking board.num or something but that isn't right. and i can't find any examples of manually initializing an array in my books.

    basically i want to know when I call up any given element of the array (board[i][j]) how do i access the 4 different elements?
    Last edited by nazgul76; 11-02-2010 at 07:10 AM.

  2. #2
    Registered User
    Join Date
    Nov 2010
    Posts
    2
    here's what i want to initialize it to:
    initialize 81 sudoku boxes
    row
    111111111
    222222222
    333333333
    444444444
    555555555
    666666666
    777777777
    888888888
    999999999

    coulmn
    123456789
    123456789
    123456789
    123456789
    123456789
    123456789
    123456789
    123456789
    123456789

    box
    111222333
    111222333
    111222333
    444555666
    444555666
    444555666
    777888999
    777888999
    777888999

    num
    actual puzzle

  3. #3
    Registered User
    Join Date
    May 2010
    Posts
    4,632
    Add a constructor to your class, initialize the arrays in the constructor.


    Jim

  4. #4
    Registered User
    Join Date
    Oct 2008
    Posts
    1,262
    You can't. Not without a hack anyway. See, the members are private, so you're not allowed to write to it from outside of the class itself.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Newbie with Very Newbie Question
    By Jedi_Mediator in forum C++ Programming
    Replies: 18
    Last Post: 07-01-2008, 08:00 AM
  2. Newbie question - struct & arrays
    By n3m0 in forum C++ Programming
    Replies: 6
    Last Post: 12-02-2006, 12:55 AM
  3. Just a quick question about character arrays
    By Welshy in forum C Programming
    Replies: 3
    Last Post: 04-03-2006, 07:20 AM
  4. Newbie Question - fflush(stdin) & fpurge(stdin) on Mac and PC
    By tvsinesperanto in forum C Programming
    Replies: 34
    Last Post: 03-11-2006, 12:13 PM
  5. Quick question: exit();
    By Cheeze-It in forum C Programming
    Replies: 6
    Last Post: 08-15-2001, 05:46 PM