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. question regarding operator overloading!

question regarding operator overloading!

Scheduled Pinned Locked Moved C / C++ / MFC
question
5 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.
  • N Offline
    N Offline
    namaskaaram
    wrote on last edited by
    #1

    can the operators 'new' and 'delete' be overloaded? "faith, hope, love remain, these three.....; but the greatest of these is love" -1 Corinthians 13:13

    J R S 3 Replies Last reply
    0
    • N namaskaaram

      can the operators 'new' and 'delete' be overloaded? "faith, hope, love remain, these three.....; but the greatest of these is love" -1 Corinthians 13:13

      J Offline
      J Offline
      Johnny
      wrote on last edited by
      #2

      Yes they can[^]!

      1 Reply Last reply
      0
      • N namaskaaram

        can the operators 'new' and 'delete' be overloaded? "faith, hope, love remain, these three.....; but the greatest of these is love" -1 Corinthians 13:13

        R Offline
        R Offline
        Rahim Rattani
        wrote on last edited by
        #3

        Yes, new and delete operators can be overloaded. Use the following signatures. 1.) new :- void* operator new( size_t p_stBlock ); 2.) delete :- void operator delete( void* p ); Rahim Rattani Software Engineer, Matrix Systems (Pvt) Ltd., Karachi - Pakistan

        1 Reply Last reply
        0
        • N namaskaaram

          can the operators 'new' and 'delete' be overloaded? "faith, hope, love remain, these three.....; but the greatest of these is love" -1 Corinthians 13:13

          S Offline
          S Offline
          S Senthil Kumar
          wrote on last edited by
          #4

          It's slightly complicated in that you can overload operator new and operator delete but you can't overload the new and delete operators in the same sense as overloading, say '+'. The reason is that your overloaded operator `new is only responsible for allocating memory, but someone must call the constructor, right? Same goes for delete, you can free memory, but someone must call the destructor. Regards Senthil _____________________________ [My Blog](http://blogs.wdevs.com/senthilkumar) | [My Articles](http://www.codeproject.com/script/articles/list_articles.asp?userid=492196) | [WinMacro](http://geocities.com/win_macro)`

          N 1 Reply Last reply
          0
          • S S Senthil Kumar

            It's slightly complicated in that you can overload operator new and operator delete but you can't overload the new and delete operators in the same sense as overloading, say '+'. The reason is that your overloaded operator `new is only responsible for allocating memory, but someone must call the constructor, right? Same goes for delete, you can free memory, but someone must call the destructor. Regards Senthil _____________________________ [My Blog](http://blogs.wdevs.com/senthilkumar) | [My Articles](http://www.codeproject.com/script/articles/list_articles.asp?userid=492196) | [WinMacro](http://geocities.com/win_macro)`

            N Offline
            N Offline
            namaskaaram
            wrote on last edited by
            #5

            Thank u senthil kumar! for ur answer!but i kinda didnt follow that last line you quoted! how is it different from the other operator overloaded types? cheerz..... "faith, hope, love remain, these three.....; but the greatest of these is love" -1 Corinthians 13:13

            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