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. two dimensional pointer array casting (C question)

two dimensional pointer array casting (C question)

Scheduled Pinned Locked Moved C / C++ / MFC
questionc++data-structureshelp
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.
  • E Offline
    E Offline
    Electronic75
    wrote on last edited by
    #1

    Hello :) , I have defined a two dimensional array of type double in one of my MFC classes in class 1: double m_aCoefficients[10][20]; and now I want to make a pointer to this variable in another of my classes and assign address of this double array to that pointer. so i have defined in class 2: double* m_pCoefficients[10][20]; and in my CMyDoc Class I have tried this: m_Class2.m_pCoefficients = (double*[10][20]) &m_Class1.m_aCoefficients; but it gives error Error 4 error C2440: 'type cast' : cannot convert from 'double (*)[10][20]' to 'double *[10][20]' How can I resolve this? thanks

    K S 2 Replies Last reply
    0
    • E Electronic75

      Hello :) , I have defined a two dimensional array of type double in one of my MFC classes in class 1: double m_aCoefficients[10][20]; and now I want to make a pointer to this variable in another of my classes and assign address of this double array to that pointer. so i have defined in class 2: double* m_pCoefficients[10][20]; and in my CMyDoc Class I have tried this: m_Class2.m_pCoefficients = (double*[10][20]) &m_Class1.m_aCoefficients; but it gives error Error 4 error C2440: 'type cast' : cannot convert from 'double (*)[10][20]' to 'double *[10][20]' How can I resolve this? thanks

      K Offline
      K Offline
      KarstenK
      wrote on last edited by
      #2

      Pointer declaration have highest priority for the compiler. As multiplication is before additiont. Example: 2*3+4=10. This is about language definition and how the compiler works. Dont know more. :(( you better double* pCoefficients; m_Class2.m_pCoefficients = (double*) &m_Class1.m_aCoefficients[0][0]; or "maybe": double[10][20]* :confused::confused::confused:

      Greetings from Germany

      1 Reply Last reply
      0
      • E Electronic75

        Hello :) , I have defined a two dimensional array of type double in one of my MFC classes in class 1: double m_aCoefficients[10][20]; and now I want to make a pointer to this variable in another of my classes and assign address of this double array to that pointer. so i have defined in class 2: double* m_pCoefficients[10][20]; and in my CMyDoc Class I have tried this: m_Class2.m_pCoefficients = (double*[10][20]) &m_Class1.m_aCoefficients; but it gives error Error 4 error C2440: 'type cast' : cannot convert from 'double (*)[10][20]' to 'double *[10][20]' How can I resolve this? thanks

        S Offline
        S Offline
        SandipG
        wrote on last edited by
        #3

        Electronic75 wrote:

        double* m_pCoefficients[10][20];

        Here you should have

        double (*m_pCoefficients)[20];

        After this you can write

        m_Class2.m_pCoefficients = m_Class1.m_aCoefficients;

        I hope it helps..

        Regards, Sandip.

        E 1 Reply Last reply
        0
        • S SandipG

          Electronic75 wrote:

          double* m_pCoefficients[10][20];

          Here you should have

          double (*m_pCoefficients)[20];

          After this you can write

          m_Class2.m_pCoefficients = m_Class1.m_aCoefficients;

          I hope it helps..

          Regards, Sandip.

          E Offline
          E Offline
          Electronic75
          wrote on last edited by
          #4

          Thanks Sandip It works fine:rose:

          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