crazy-arse array code that i need help with -- whats wrong with this?

This is a discussion on crazy-arse array code that i need help with -- whats wrong with this? within the C++ Programming forums, part of the General Programming Boards category; Alright, here is the code: Code: struct LEVELINFO { int (*level)[BLOCK_GRID_ROWS][BLOCK_GRID_COLUMNS]; }; //ind = (*(lev[current_level].level + rowcounter))[colcounter]; //ind = *(*(lev[current_level].level ...

  1. #1
    Unregistered Leeman_s's Avatar
    Join Date
    Oct 2001
    Posts
    753

    crazy-arse array code that i need help with -- whats wrong with this?

    Alright, here is the code:
    Code:
    struct LEVELINFO
    {
    	int (*level)[BLOCK_GRID_ROWS][BLOCK_GRID_COLUMNS];
    };
    
    //ind = (*(lev[current_level].level + rowcounter))[colcounter];
    		//ind = *(*(lev[current_level].level + rowcounter) + colcounter);
    		ind = *(lev[current_level].level[rowcounter] + colcounter);
    I tried all 3 of those lines and they all give this error:

    error C2440: '=' : cannot convert from 'int [22]' to 'int'
    This conversion requires a reinterpret_cast, a C-style cast or function-style cast

  2. #2
    Programming Sex-God Polymorphic OOP's Avatar
    Join Date
    Nov 2002
    Posts
    1,078
    post the declarations of the variables and what you want it to do, otherwise we can't help you.

  3. #3
    Unregistered Leeman_s's Avatar
    Join Date
    Oct 2001
    Posts
    753
    Code:
    int lev1[BLOCK_GRID_ROWS][BLOCK_GRID_COLUMNS] =
    	{
    		{1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1},
    		{1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1},
    		{1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1},
    		{1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1},
    		{1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1},
    		{1,1,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,1,1},
    		{1,1,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,1,1},
    		{1,1,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,1,1},
    		{1,1,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,1,1},
    		{1,1,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,1,1},
    		{1,1,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,1,1},
    		{1,1,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,1,1},
    		{1,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,1},
    		{1,0,0,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,0,0,1},
    		{1,0,0,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,0,0,1},
    		{1,0,0,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,0,0,1},
    		{1,0,0,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,0,0,1},
    		{1,0,0,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,0,0,1},
    		{0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0},
    		{1,1,2,2,3,3,3,3,3,3,3,3,3,3,3,3,3,3,2,2,1,1},
    	};
    
    LEVELINFO lev[5];
    int current_level = 1;
    
    void InitLevels()
    {
    	lev[0].level = &lev1;
    	lev[1].level = &lev1;
    	lev[2].level = &lev1;
    	lev[3].level = &lev1;
    	lev[4].level = &lev1;
    }
    
    int ind = 0;
    
    //ind = (*(lev[current_level].level + rowcounter))[colcounter];
    //ind = *(*(lev[current_level].level + rowcounter) + colcounter);
    ind = *(lev[current_level].level[rowcounter] + colcounter);
    is that enough?

  4. #4
    Programming Sex-God Polymorphic OOP's Avatar
    Join Date
    Nov 2002
    Posts
    1,078
    ind = (*lev[current_level].level)[rowcounter][colcounter];

    Just think through logcially what you are doing and you shouldn't have too much trouble.

    You're accessing the current_level element of lev and accessing its level pointer. You want to dereference that. The result of that is like a reference to the array, then you want to access that array's element of row rowcounter and column colcounter.
    Last edited by Polymorphic OOP; 01-19-2003 at 03:11 PM.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Trimming the fat out of my code for an Array
    By katipo in forum C Programming
    Replies: 17
    Last Post: 12-09-2008, 12:47 PM
  2. Class Template Trouble
    By pliang in forum C++ Programming
    Replies: 4
    Last Post: 04-21-2005, 04:15 AM
  3. Obfuscated Code Contest
    By Stack Overflow in forum Contests Board
    Replies: 51
    Last Post: 01-21-2005, 03:17 PM
  4. Trying to make this code faster & Cramer
    By just2peachy in forum C++ Programming
    Replies: 3
    Last Post: 12-03-2004, 09:54 AM
  5. Array Program
    By emmx in forum C Programming
    Replies: 3
    Last Post: 08-31-2003, 12:44 AM

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21