Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. General Programming
  3. C / C++ / MFC
  4. Matrices

Matrices

Scheduled Pinned Locked Moved C / C++ / MFC
helpdata-structuresquestion
4 Posts 3 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • A Offline
    A Offline
    Albedo
    wrote on last edited by
    #1

    Ok, this may sound rather dumb, but this problem is irritating me greatly: In using the CButtonST class I declared this in my code: CButtonST *buttonArray[10][20] One would normally think that this would create a 10x20 matrix, but in my program it creates a 20x10 matrix instead! Does anyone know why this is so? I tried to make a different array of the same size, but it too was reversed. Is there something that I'm missing in my code? Any help would be much appreciated.

    I 1 Reply Last reply
    0
    • A Albedo

      Ok, this may sound rather dumb, but this problem is irritating me greatly: In using the CButtonST class I declared this in my code: CButtonST *buttonArray[10][20] One would normally think that this would create a 10x20 matrix, but in my program it creates a 20x10 matrix instead! Does anyone know why this is so? I tried to make a different array of the same size, but it too was reversed. Is there something that I'm missing in my code? Any help would be much appreciated.

      I Offline
      I Offline
      imsniper
      wrote on last edited by
      #2

      Taken from MSDN...... Array An array is a collection of like objects. The simplest case of an array is a vector. C++ provides a convenient syntax for declaration of fixed-size arrays: Syntax decl-specifiers dname [ constant-expressionopt ] ; The number of elements in the array is given by the constant-expression. The first element in the array is the 0th element, and the last element is the (n-1th) element, where n is the size of the array. The constant-expression must be of an integral type and must be greater than 0. A zero-sized array is legal only when the array is the last field in a struct or union and when the Microsoft extensions (/Ze) are enabled. Arrays are derived types and can therefore be constructed from any other derived or fundamental type except functions, references, and void. Arrays constructed from other arrays are multidimensional arrays. These multidimensional arrays are specified by placing multiple [ constant-expression ] specifications in sequence. For example, consider this declaration: int i2[5][7]; It specifies an array of type int, conceptually arranged in a two-dimensional matrix of five rows and seven columns 5 ROWS X 7 COLUMNS!

      A 1 Reply Last reply
      0
      • I imsniper

        Taken from MSDN...... Array An array is a collection of like objects. The simplest case of an array is a vector. C++ provides a convenient syntax for declaration of fixed-size arrays: Syntax decl-specifiers dname [ constant-expressionopt ] ; The number of elements in the array is given by the constant-expression. The first element in the array is the 0th element, and the last element is the (n-1th) element, where n is the size of the array. The constant-expression must be of an integral type and must be greater than 0. A zero-sized array is legal only when the array is the last field in a struct or union and when the Microsoft extensions (/Ze) are enabled. Arrays are derived types and can therefore be constructed from any other derived or fundamental type except functions, references, and void. Arrays constructed from other arrays are multidimensional arrays. These multidimensional arrays are specified by placing multiple [ constant-expression ] specifications in sequence. For example, consider this declaration: int i2[5][7]; It specifies an array of type int, conceptually arranged in a two-dimensional matrix of five rows and seven columns 5 ROWS X 7 COLUMNS!

        A Offline
        A Offline
        Albedo
        wrote on last edited by
        #3

        That's not my problem though. I know what a matrix is and how to declare one; it's that my CButtonST *buttonArray[10][20] matrix is making a matrix of 20 rows X 10 columns, which is in the wrong order.

        D 1 Reply Last reply
        0
        • A Albedo

          That's not my problem though. I know what a matrix is and how to declare one; it's that my CButtonST *buttonArray[10][20] matrix is making a matrix of 20 rows X 10 columns, which is in the wrong order.

          D Offline
          D Offline
          David Chamberlain
          wrote on last edited by
          #4

          Since you haven't given much detail, here is just a wild stab. I am assuming you are thinking in your code not of "row" and "column" but perhaps as "x" and "y". What you have written ("buttonArray[10][20]") we know to be 10 rows of 20 columns, but if you think of it as "x" and "y" you may get your loop indexes reversed. Since "x" and "y" relate to a Cartesian coordinate system, the "x" axis is typically the horizontal axis, but it actually measures columns (which increase horizontally). Likewise, "y" is the vertical axis and it measures rows. Therefore, and again this is just a wild stab, if you are programming using "x" and "y" as your loop index variables, you are going to want to reference elements in the array as "buttonArray[y][x]" just as you would if you were using "row" and "col" (buttonArray[row][col]). What is it that is telling you that the array is actually [20][10] instead of [10][20]? Dave "You can say that again." -- Dept. of Redundancy Dept.

          1 Reply Last reply
          0
          Reply
          • Reply as topic
          Log in to reply
          • Oldest to Newest
          • Newest to Oldest
          • Most Votes


          • Login

          • Don't have an account? Register

          • Login or register to search.
          • First post
            Last post
          0
          • Categories
          • Recent
          • Tags
          • Popular
          • World
          • Users
          • Groups