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. C++ question

C++ question

Scheduled Pinned Locked Moved C / C++ / MFC
questionc++data-structures
6 Posts 4 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.
  • R Offline
    R Offline
    Rajveer
    wrote on last edited by
    #1

    If I have an array: double xcoord[80]; I can pass it to a function and the function can receive it as a pointer... void AcceptArray(double* ) but how do I write the function prototype if that array were multidimensional, say -- xcoord[80][10]

    P W P 3 Replies Last reply
    0
    • R Rajveer

      If I have an array: double xcoord[80]; I can pass it to a function and the function can receive it as a pointer... void AcceptArray(double* ) but how do I write the function prototype if that array were multidimensional, say -- xcoord[80][10]

      P Offline
      P Offline
      Paul M Watt
      wrote on last edited by
      #2

      Send it in as you would with a single dimensional array: void AcceptArray(double *array) but when you use it inside of your function, calculate the index that the two values would point to: // access array[x][y], array[(y * width) + x ] where width is the number of columns, or x values in one row.


      Checkout my Guide to Win32 Paint for Intermediates

      R 1 Reply Last reply
      0
      • R Rajveer

        If I have an array: double xcoord[80]; I can pass it to a function and the function can receive it as a pointer... void AcceptArray(double* ) but how do I write the function prototype if that array were multidimensional, say -- xcoord[80][10]

        W Offline
        W Offline
        woods13
        wrote on last edited by
        #3

        void AcceptArray(double var[][10]) ; That should do the trick. //------------------------   CSignature::Jeff() ;   PostMessage(WM_QUIT) ; //------------------------

        1 Reply Last reply
        0
        • P Paul M Watt

          Send it in as you would with a single dimensional array: void AcceptArray(double *array) but when you use it inside of your function, calculate the index that the two values would point to: // access array[x][y], array[(y * width) + x ] where width is the number of columns, or x values in one row.


          Checkout my Guide to Win32 Paint for Intermediates

          R Offline
          R Offline
          Rajveer
          wrote on last edited by
          #4

          okay, I have this array: double x_coord1[80][10]; this is one of my function prototypes: void NewCoordinates(double* xcoord1, double* ycoord1, int global_numcoord1, double* x_coord1, double* y_coord1); and when I call on the function like so: NewCoordinates(xcoord1, ycoord1, global_numcoord1, x_coord1, y_coord1); I get this error: C:\Windows\Desktop\QE2 heart program\TestGLView.cpp(460) : error C2664: 'NewCoordinates' : cannot convert parameter 4 from 'double [80][10]' to 'double *' what am I doing wrong?

          P 1 Reply Last reply
          0
          • R Rajveer

            If I have an array: double xcoord[80]; I can pass it to a function and the function can receive it as a pointer... void AcceptArray(double* ) but how do I write the function prototype if that array were multidimensional, say -- xcoord[80][10]

            P Offline
            P Offline
            PJ Arends
            wrote on last edited by
            #5

            void Accept2DArray (double **); HTH --- CPUA 0x5041 Sonork 100.11743 Chicken Little It may be that your sole purpose in life is simply to serve as a warning to others.

            1 Reply Last reply
            0
            • R Rajveer

              okay, I have this array: double x_coord1[80][10]; this is one of my function prototypes: void NewCoordinates(double* xcoord1, double* ycoord1, int global_numcoord1, double* x_coord1, double* y_coord1); and when I call on the function like so: NewCoordinates(xcoord1, ycoord1, global_numcoord1, x_coord1, y_coord1); I get this error: C:\Windows\Desktop\QE2 heart program\TestGLView.cpp(460) : error C2664: 'NewCoordinates' : cannot convert parameter 4 from 'double [80][10]' to 'double *' what am I doing wrong?

              P Offline
              P Offline
              Paul M Watt
              wrote on last edited by
              #6

              I am sorry, I was writing a test program to make sure that I gave you good advice, and I was distracted in the middle. When I came back to write my message to you, I assumed that the code that I got was working. Woods13 gives the correct way to do it: double x[][80] or double **x The way that I suggested is for dynamic arrays that are declared like this: double x[20 * 80]; then your array is one dimensional.


              Checkout my Guide to Win32 Paint for Intermediates

              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