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. Easy OO question

Easy OO question

Scheduled Pinned Locked Moved C / C++ / MFC
questioncsharpcom
3 Posts 3 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 Hooper
    wrote on last edited by
    #1

    class Foo
    {
    Foo();
    ~Foo();

    };

    Foo *bar = new Foo;

    delete bar;

    The destructor is called when I delete bar right? - Jason (SonorkID 100.611) In the beginning, teachers taught the 5 W's: who, what, where, when, why. Now it's just a big damn G

    F R 2 Replies Last reply
    0
    • J Jason Hooper

      class Foo
      {
      Foo();
      ~Foo();

      };

      Foo *bar = new Foo;

      delete bar;

      The destructor is called when I delete bar right? - Jason (SonorkID 100.611) In the beginning, teachers taught the 5 W's: who, what, where, when, why. Now it's just a big damn G

      F Offline
      F Offline
      Fred D
      wrote on last edited by
      #2

      as it is in the MSDN : When delete is used to deallocate memory for a C++ class object, the object's destructor is called before the object's memory is deallocated (if the object has a destructor). Fred

      1 Reply Last reply
      0
      • J Jason Hooper

        class Foo
        {
        Foo();
        ~Foo();

        };

        Foo *bar = new Foo;

        delete bar;

        The destructor is called when I delete bar right? - Jason (SonorkID 100.611) In the beginning, teachers taught the 5 W's: who, what, where, when, why. Now it's just a big damn G

        R Offline
        R Offline
        Rage
        wrote on last edited by
        #3

        Jason Hooper wrote: The destructor is called when I delete bar right? yep. If you want to make sure of it, just try to display something in the destructor [ with

        ~Foo{ cout<<"Here i destruct the object"< if you're running a console application].You can even display the pointer address to be really sure it is the bar and not something else.

        ~RaGE();

        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