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. help me

help me

Scheduled Pinned Locked Moved C / C++ / MFC
helpquestion
9 Posts 6 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.
  • G Offline
    G Offline
    gentleguy
    wrote on last edited by
    #1

    dear all any problem occurred when the following errers happened? : error C2057: expected constant expression thanks

    Li Zhiyuan 5/10/2006

    C K H 3 Replies Last reply
    0
    • G gentleguy

      dear all any problem occurred when the following errers happened? : error C2057: expected constant expression thanks

      Li Zhiyuan 5/10/2006

      C Offline
      C Offline
      Cedric Moonen
      wrote on last edited by
      #2

      Well, the error message is clear enough no ? It says that somewhere the compiler expects a constant variable but you didn't provide it. And without any piece of code, it is impossible to tell more.

      Cédric Moonen Software developer
      Charting control [v1.2]

      1 Reply Last reply
      0
      • G gentleguy

        dear all any problem occurred when the following errers happened? : error C2057: expected constant expression thanks

        Li Zhiyuan 5/10/2006

        K Offline
        K Offline
        kingori
        wrote on last edited by
        #3

        hi; most likely you have declared an array without indicating its size e.g long m_lStudents[]; if thats the case then give it size;

        1 Reply Last reply
        0
        • G gentleguy

          dear all any problem occurred when the following errers happened? : error C2057: expected constant expression thanks

          Li Zhiyuan 5/10/2006

          H Offline
          H Offline
          Hamid Taebi
          wrote on last edited by
          #4

          Is this question related to your previous question?

          G 1 Reply Last reply
          0
          • H Hamid Taebi

            Is this question related to your previous question?

            G Offline
            G Offline
            gentleguy
            wrote on last edited by
            #5

            no, this is what i just studied for dynamic multiple array...the code is here.... nt n,m; double c[n][m] = NULL; double * a[] = NULL; double * b[] = NULL; cin >> n; cin>>m; b[] = new double[m]; a[] = new double[n]; for (int i=0; i>>n; i++) { a[i] =(double) rand()/RAND_MAX; } for (int j=0; j{ a[j] =(double) rand()/RAND_MAX; } for (int k=0;k for (int kk=0;kk { if (k==0) c[k][kk] = a[k]; else c[k][kk] = b[kk]; } cout <<"\n"; delete [] a; a = NULL; } this is what i created a 2 D dynamic array...but the problem is there...how to create a 2D dynamic array? thanks

            Li Zhiyuan 5/10/2006

            I 1 Reply Last reply
            0
            • G gentleguy

              no, this is what i just studied for dynamic multiple array...the code is here.... nt n,m; double c[n][m] = NULL; double * a[] = NULL; double * b[] = NULL; cin >> n; cin>>m; b[] = new double[m]; a[] = new double[n]; for (int i=0; i>>n; i++) { a[i] =(double) rand()/RAND_MAX; } for (int j=0; j{ a[j] =(double) rand()/RAND_MAX; } for (int k=0;k for (int kk=0;kk { if (k==0) c[k][kk] = a[k]; else c[k][kk] = b[kk]; } cout <<"\n"; delete [] a; a = NULL; } this is what i created a 2 D dynamic array...but the problem is there...how to create a 2D dynamic array? thanks

              Li Zhiyuan 5/10/2006

              I Offline
              I Offline
              Iain Clarke Warrior Programmer
              wrote on last edited by
              #6

              li zhiyuan wrote:

              how to create a 2D dynamic array?

              Simple answer... You can't. Which is why you're getting an error. Longer answer... You cheat. Create a one dimensional dynamic array. But make it an array of double *s, then create those arrays.

              typedef double *pdouble;

              // create a 2D virtual array
              pdouble *c = new pdouble [N];
              for (n = 0; n < N; n++)
              c [n] = new double [m];

              .... ; do your processing code

              // Tidy up 2D virtual array
              for (n = 0; n < N; n++)
              delete [] c [n];
              delete [] c;

              Notice I'm using delete [] instead of delete. The [] means it will call the destructor for each member of the array(s). For simple types like double and double *, it makes no difference. But it makes no harm, and is a good habit to get into. Then you can make arrays of classes/structs that *could* have destructors, and you'll be thankful for your good habits. I hope that helped, Iain. ps, In addition, please use the <pre> / </pre> keywords in your posts. And longer variables. They're hard to read now, and you're going to hate yourself in two years time.

              G 1 Reply Last reply
              0
              • I Iain Clarke Warrior Programmer

                li zhiyuan wrote:

                how to create a 2D dynamic array?

                Simple answer... You can't. Which is why you're getting an error. Longer answer... You cheat. Create a one dimensional dynamic array. But make it an array of double *s, then create those arrays.

                typedef double *pdouble;

                // create a 2D virtual array
                pdouble *c = new pdouble [N];
                for (n = 0; n < N; n++)
                c [n] = new double [m];

                .... ; do your processing code

                // Tidy up 2D virtual array
                for (n = 0; n < N; n++)
                delete [] c [n];
                delete [] c;

                Notice I'm using delete [] instead of delete. The [] means it will call the destructor for each member of the array(s). For simple types like double and double *, it makes no difference. But it makes no harm, and is a good habit to get into. Then you can make arrays of classes/structs that *could* have destructors, and you'll be thankful for your good habits. I hope that helped, Iain. ps, In addition, please use the <pre> / </pre> keywords in your posts. And longer variables. They're hard to read now, and you're going to hate yourself in two years time.

                G Offline
                G Offline
                gentleguy
                wrote on last edited by
                #7

                thanks a lot friend, could you provide me with complete code creating 2 D dynamic array? thanks again

                Li Zhiyuan

                I D 2 Replies Last reply
                0
                • G gentleguy

                  thanks a lot friend, could you provide me with complete code creating 2 D dynamic array? thanks again

                  Li Zhiyuan

                  I Offline
                  I Offline
                  Iain Clarke Warrior Programmer
                  wrote on last edited by
                  #8

                  I already did provide you with complete code for creating a 2d array, and then destroying it. Look at the post you replied to.

                  1 Reply Last reply
                  0
                  • G gentleguy

                    thanks a lot friend, could you provide me with complete code creating 2 D dynamic array? thanks again

                    Li Zhiyuan

                    D Offline
                    D Offline
                    David Crow
                    wrote on last edited by
                    #9

                    Please remove your blinders. :rolleyes:

                    "Normal is getting dressed in clothes that you buy for work and driving through traffic in a car that you are still paying for, in order to get to the job you need to pay for the clothes and the car and the house you leave vacant all day so you can afford to live in it." - Ellen Goodman

                    "To have a respect for ourselves guides our morals; to have deference for others governs our manners." - Laurence Sterne

                    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