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

need help

Scheduled Pinned Locked Moved C / C++ / MFC
helpdata-structures
8 Posts 5 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 my problem is below, anyone help me to check, thanks a lot. T,sigma,maskSize,halfSize are all declared. for (int k=0;k<5;k++) { halfSize = static_cast(sqrt(-log(T))*2*pow(sigma[k],2)); maskSize = 2*halfSize + 1; int Mask[k][maskSize][maskSize]; int valueX[k][maskSize][maskSize]; int valueY[k][maskSize][maskSize]; } error C2057: expected constant expression error C2466: cannot allocate an array of constant size 0 so anyone help me. thanks

    Li Zhiyuan

    C C 2 Replies Last reply
    0
    • G gentleguy

      dear all my problem is below, anyone help me to check, thanks a lot. T,sigma,maskSize,halfSize are all declared. for (int k=0;k<5;k++) { halfSize = static_cast(sqrt(-log(T))*2*pow(sigma[k],2)); maskSize = 2*halfSize + 1; int Mask[k][maskSize][maskSize]; int valueX[k][maskSize][maskSize]; int valueY[k][maskSize][maskSize]; } error C2057: expected constant expression error C2466: cannot allocate an array of constant size 0 so anyone help me. thanks

      Li Zhiyuan

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

      If you want to allocate an array from which you don't know the size at compile time (you only know it at runtime), then you need to use new. It is quite basic C++ stuff and it is not the first time you ask that question (even if people already answered you). I think it would be great for you to learn C++ from the start. So, buy a good book and take some time to learn it correctly. You might spend some time on it but at the end, you will be much more efficient. Just an advice though...

      Cédric Moonen Software developer
      Charting control [v1.3 - Updated]

      G 1 Reply Last reply
      0
      • C Cedric Moonen

        If you want to allocate an array from which you don't know the size at compile time (you only know it at runtime), then you need to use new. It is quite basic C++ stuff and it is not the first time you ask that question (even if people already answered you). I think it would be great for you to learn C++ from the start. So, buy a good book and take some time to learn it correctly. You might spend some time on it but at the end, you will be much more efficient. Just an advice though...

        Cédric Moonen Software developer
        Charting control [v1.3 - Updated]

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

        thanks, i already bought c++ fifth edition book, but so few pages to introduce new and delete, any code or stuff are available for me? thanks a lot

        Li Zhiyuan

        1 Reply Last reply
        0
        • G gentleguy

          dear all my problem is below, anyone help me to check, thanks a lot. T,sigma,maskSize,halfSize are all declared. for (int k=0;k<5;k++) { halfSize = static_cast(sqrt(-log(T))*2*pow(sigma[k],2)); maskSize = 2*halfSize + 1; int Mask[k][maskSize][maskSize]; int valueX[k][maskSize][maskSize]; int valueY[k][maskSize][maskSize]; } error C2057: expected constant expression error C2466: cannot allocate an array of constant size 0 so anyone help me. thanks

          Li Zhiyuan

          C Offline
          C Offline
          Cranky
          wrote on last edited by
          #4

          Which part of "Read the forum guidelines" do you not understand? Each time you use these idiotic subject lines "Need Help", "Urgent!!!!! Help!!!!!!!!!!!!!!!!!", etc. you are told to use subject lines that actually describe the problem briefly but you simply refuse to do that. Not to mention that this has been going on for almost 2 years. What is your malfunction?

          G R 2 Replies Last reply
          0
          • C Cranky

            Which part of "Read the forum guidelines" do you not understand? Each time you use these idiotic subject lines "Need Help", "Urgent!!!!! Help!!!!!!!!!!!!!!!!!", etc. you are told to use subject lines that actually describe the problem briefly but you simply refuse to do that. Not to mention that this has been going on for almost 2 years. What is your malfunction?

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

            thanks sir.do you have any such stuff or code? thanks

            Li Zhiyuan

            C T 2 Replies Last reply
            0
            • C Cranky

              Which part of "Read the forum guidelines" do you not understand? Each time you use these idiotic subject lines "Need Help", "Urgent!!!!! Help!!!!!!!!!!!!!!!!!", etc. you are told to use subject lines that actually describe the problem briefly but you simply refuse to do that. Not to mention that this has been going on for almost 2 years. What is your malfunction?

              R Offline
              R Offline
              Rajesh R Subramanian
              wrote on last edited by
              #6

              Cranky wrote:

              Not to mention that this has been going on for almost 2 years.

              :laugh: But, I think he is not a native English speaker. However, 2 years into CP and that won't make an excuse. :)

              Nobody can give you wiser advice than yourself. - Cicero .·´¯`·->Rajesh<-·´¯`·. Codeproject.com: Visual C++ MVP

              1 Reply Last reply
              0
              • G gentleguy

                thanks sir.do you have any such stuff or code? thanks

                Li Zhiyuan

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

                int** myArray; // An uninitialized 2D array, cannot be used this way.

                myArray = new int*[10]; // Creates an array of 10 pointers to integer.
                // Each of these 10 pointers are not initialized, so again, not usable.

                for (int i=0;i<10;i++)
                {
                myArray[i] = new int[20]; // For each of these 10 pointers, we allocate an array of 20 integers.
                }

                So, now you have a 2D array. Don't forget to delete everything once you are done. Here the same applies: you need to delete each row first and then delete the root pointer. I leave you that as an exercice to see if you understand the concept ;) .

                Cédric Moonen Software developer
                Charting control [v1.3 - Updated]

                1 Reply Last reply
                0
                • G gentleguy

                  thanks sir.do you have any such stuff or code? thanks

                  Li Zhiyuan

                  T Offline
                  T Offline
                  ThatsAlok
                  wrote on last edited by
                  #8

                  what about vector vector combination!

                  "Opinions are neither right nor wrong. I cannot change your opinion. I can, however, change what influences your opinion." - David Crow
                  Never mind - my own stupidity is the source of every "problem" - Mixture

                  cheers, Alok Gupta VC Forum Q&A :- I/IV Support CRY- Child Relief and You/codeProject$$>

                  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