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. Forcing new to fail [modified]

Forcing new to fail [modified]

Scheduled Pinned Locked Moved C / C++ / MFC
questionperformance
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.
  • H Offline
    H Offline
    hint_54
    wrote on last edited by
    #1

    Hi all =) Is there a way of forcing the operator new to fail?? I need to test something... Best regards [[]] hint_54 -- modified at 18:06 Wednesday 31st May, 2006 Oh.. and one more thing =D If I overload the operator new then the class constructors will not be called when memory is allocated for them. How do I make it call the constructor? Peace =) hint_54

    J S D 3 Replies Last reply
    0
    • H hint_54

      Hi all =) Is there a way of forcing the operator new to fail?? I need to test something... Best regards [[]] hint_54 -- modified at 18:06 Wednesday 31st May, 2006 Oh.. and one more thing =D If I overload the operator new then the class constructors will not be called when memory is allocated for them. How do I make it call the constructor? Peace =) hint_54

      J Offline
      J Offline
      Jorgen Sigvardsson
      wrote on last edited by
      #2

      hint_54 wrote:

      If I overload the operator new then the class constructors will not be called when memory is allocated for them. How do I make it call the constructor?

      Placement new? new (ptr_to_memory) Class(args)

      -- 100% natural. No superstitious additives.

      1 Reply Last reply
      0
      • H hint_54

        Hi all =) Is there a way of forcing the operator new to fail?? I need to test something... Best regards [[]] hint_54 -- modified at 18:06 Wednesday 31st May, 2006 Oh.. and one more thing =D If I overload the operator new then the class constructors will not be called when memory is allocated for them. How do I make it call the constructor? Peace =) hint_54

        S Offline
        S Offline
        Stephen Hewitt
        wrote on last edited by
        #3

        Overloading the new should not effect whether the constructor is called. Steve

        H 1 Reply Last reply
        0
        • H hint_54

          Hi all =) Is there a way of forcing the operator new to fail?? I need to test something... Best regards [[]] hint_54 -- modified at 18:06 Wednesday 31st May, 2006 Oh.. and one more thing =D If I overload the operator new then the class constructors will not be called when memory is allocated for them. How do I make it call the constructor? Peace =) hint_54

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

          hint_54 wrote:

          If I overload the operator new then the class constructors will not be called when memory is allocated for them.

          How are you verifying this?


          "The largest fire starts but with the smallest spark." - David Crow

          H 1 Reply Last reply
          0
          • D David Crow

            hint_54 wrote:

            If I overload the operator new then the class constructors will not be called when memory is allocated for them.

            How are you verifying this?


            "The largest fire starts but with the smallest spark." - David Crow

            H Offline
            H Offline
            hint_54
            wrote on last edited by
            #5

            I add a printf to the constructor. But I don't get it.. it wasn't calling it and now it is! It must have been something else.. regards hint_54

            1 Reply Last reply
            0
            • S Stephen Hewitt

              Overloading the new should not effect whether the constructor is called. Steve

              H Offline
              H Offline
              hint_54
              wrote on last edited by
              #6

              Yes.. It's working now, but it didn't work at first.. Don't know why.. regards hint_54

              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