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. "Scalar deleting destructor" error

"Scalar deleting destructor" error

Scheduled Pinned Locked Moved C / C++ / MFC
questionc++data-structuresdebuggingperformance
10 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.
  • J Offline
    J Offline
    Jason Hihn
    wrote on last edited by
    #1

    I have code that looks like: CArray ArrayOfObjPtrs; ObjPtr op=new Obj(); ArrayOfObjPtrs.Add(op); Then in another function called later in the same thread, I do: delete ArrayOfObjPtrs.GetAt(0); // free the object ** run-time error on this line ** ArrayOfObjPtrs.RemoveAt(0); the Run-time error is in MSVCRTD, but the last call of mine is on the stack right before it, is "Obj::`scalar deleting desctructor' (unsigned int 1) + 56 bytes I get a Debug Asseertion: dbgdel.cpp Line 47, Expression _BLOCK_TYPE_IS_VALID(pHead->nBlockUse) Can anyone please tell me what is going on? Thanks soooo much! PS. Commenting out the 'delete' line results in a memory leak

    P R L 3 Replies Last reply
    0
    • J Jason Hihn

      I have code that looks like: CArray ArrayOfObjPtrs; ObjPtr op=new Obj(); ArrayOfObjPtrs.Add(op); Then in another function called later in the same thread, I do: delete ArrayOfObjPtrs.GetAt(0); // free the object ** run-time error on this line ** ArrayOfObjPtrs.RemoveAt(0); the Run-time error is in MSVCRTD, but the last call of mine is on the stack right before it, is "Obj::`scalar deleting desctructor' (unsigned int 1) + 56 bytes I get a Debug Asseertion: dbgdel.cpp Line 47, Expression _BLOCK_TYPE_IS_VALID(pHead->nBlockUse) Can anyone please tell me what is going on? Thanks soooo much! PS. Commenting out the 'delete' line results in a memory leak

      P Offline
      P Offline
      Prem Kumar
      wrote on last edited by
      #2

      Probabaly you could remove the element first and then delete it next using an intermediatery temp variable.

      J 1 Reply Last reply
      0
      • P Prem Kumar

        Probabaly you could remove the element first and then delete it next using an intermediatery temp variable.

        J Offline
        J Offline
        Jason Hihn
        wrote on last edited by
        #3

        What effect would that have?

        1 Reply Last reply
        0
        • J Jason Hihn

          I have code that looks like: CArray ArrayOfObjPtrs; ObjPtr op=new Obj(); ArrayOfObjPtrs.Add(op); Then in another function called later in the same thread, I do: delete ArrayOfObjPtrs.GetAt(0); // free the object ** run-time error on this line ** ArrayOfObjPtrs.RemoveAt(0); the Run-time error is in MSVCRTD, but the last call of mine is on the stack right before it, is "Obj::`scalar deleting desctructor' (unsigned int 1) + 56 bytes I get a Debug Asseertion: dbgdel.cpp Line 47, Expression _BLOCK_TYPE_IS_VALID(pHead->nBlockUse) Can anyone please tell me what is going on? Thanks soooo much! PS. Commenting out the 'delete' line results in a memory leak

          R Offline
          R Offline
          Rama Krishna Vavilala
          wrote on last edited by
          #4

          How does the class ObjPtr look? Looks to me that there is some sort of a casting problem. I feel that ArrayOfObjPtrs.GetAt(0) is not returning Obj* for some reason.

          J 1 Reply Last reply
          0
          • R Rama Krishna Vavilala

            How does the class ObjPtr look? Looks to me that there is some sort of a casting problem. I feel that ArrayOfObjPtrs.GetAt(0) is not returning Obj* for some reason.

            J Offline
            J Offline
            Jason Hihn
            wrote on last edited by
            #5

            new() returns a pointer This pointer to the object, not the object itself, is stored in the CArray

            R 1 Reply Last reply
            0
            • R Rama Krishna Vavilala

              What is ObjPtr is it a class or there was a typo in the original mail ObjPtr op = new Obj(); or is it Obj* op = new Obj(); How does you ObjPtr class look?

              J Offline
              J Offline
              Jason Hihn
              wrote on last edited by
              #6

              Im my example, they both are the same. ObjPtr is a Obj * Sorry for the abiguity.

              B W 2 Replies Last reply
              0
              • J Jason Hihn

                new() returns a pointer This pointer to the object, not the object itself, is stored in the CArray

                R Offline
                R Offline
                Rama Krishna Vavilala
                wrote on last edited by
                #7

                What is ObjPtr is it a class or there was a typo in the original mail ObjPtr op = new Obj(); or is it Obj* op = new Obj(); How does you ObjPtr class look?

                J 1 Reply Last reply
                0
                • J Jason Hihn

                  Im my example, they both are the same. ObjPtr is a Obj * Sorry for the abiguity.

                  B Offline
                  B Offline
                  Bill Wilson
                  wrote on last edited by
                  #8

                  Try telling the CArray what kind of thing you will be storing in it. For example if you were storing pointers to CString objects, you would define it like this: CArray myArray;

                  1 Reply Last reply
                  0
                  • J Jason Hihn

                    Im my example, they both are the same. ObjPtr is a Obj * Sorry for the abiguity.

                    W Offline
                    W Offline
                    wqw
                    wrote on last edited by
                    #9

                    i usually get this error when trying to delete a ptr to an object allocated on the stack. you'll have to check your code (esp. typedef's in yout case: ?ObjPtr?) HTH,

                    1 Reply Last reply
                    0
                    • J Jason Hihn

                      I have code that looks like: CArray ArrayOfObjPtrs; ObjPtr op=new Obj(); ArrayOfObjPtrs.Add(op); Then in another function called later in the same thread, I do: delete ArrayOfObjPtrs.GetAt(0); // free the object ** run-time error on this line ** ArrayOfObjPtrs.RemoveAt(0); the Run-time error is in MSVCRTD, but the last call of mine is on the stack right before it, is "Obj::`scalar deleting desctructor' (unsigned int 1) + 56 bytes I get a Debug Asseertion: dbgdel.cpp Line 47, Expression _BLOCK_TYPE_IS_VALID(pHead->nBlockUse) Can anyone please tell me what is going on? Thanks soooo much! PS. Commenting out the 'delete' line results in a memory leak

                      L Offline
                      L Offline
                      Lost User
                      wrote on last edited by
                      #10

                      Hope u're not doing something like: delete this; within the destructor. It may have destroyed the pointer when u exited the function within which u did the allocation. That's a rather strange characteristic of C++. If that's not the case then u may have destroyed the object somewhere else without realizing it,otherwise there's no reason the above code should throw that exception.

                      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