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. problem with delete

problem with delete

Scheduled Pinned Locked Moved C / C++ / MFC
c++debugginghelpquestion
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.
  • A Offline
    A Offline
    Arjan Schouten
    wrote on last edited by
    #1

    What's wrong with this piece of code? The destructor of Class Value is never been called! If I try to set a breakpoint there, the compiler immediately disables it. What am I doing here that's against the rules?

    .h file

    class Value
    {
    public:
    unsigned char *pvalue;

    Value(int size)
    {
    pvalue=new unsigned char(size);
    }
    ~Value()
    {
    delete [] pvalue; <-- No break point here
    }
    };

    class Parameter
    {
    public:
    CString Name;
    CString MenuItem;
    void *pValue;
    void *ValueText;
    Parameter *next;
    Parameter()
    {
    pValue = NULL;
    next = NULL;
    }
    ~Parameter()
    {
    if(pValue)
    delete pValue;
    }
    };

    .cpp file

    Parameter* Parm = new Parameter();
    Parm->pValue = new Value(4);
    delete Parm;

    Thanks, Arjan

    C J 2 Replies Last reply
    0
    • A Arjan Schouten

      What's wrong with this piece of code? The destructor of Class Value is never been called! If I try to set a breakpoint there, the compiler immediately disables it. What am I doing here that's against the rules?

      .h file

      class Value
      {
      public:
      unsigned char *pvalue;

      Value(int size)
      {
      pvalue=new unsigned char(size);
      }
      ~Value()
      {
      delete [] pvalue; <-- No break point here
      }
      };

      class Parameter
      {
      public:
      CString Name;
      CString MenuItem;
      void *pValue;
      void *ValueText;
      Parameter *next;
      Parameter()
      {
      pValue = NULL;
      next = NULL;
      }
      ~Parameter()
      {
      if(pValue)
      delete pValue;
      }
      };

      .cpp file

      Parameter* Parm = new Parameter();
      Parm->pValue = new Value(4);
      delete Parm;

      Thanks, Arjan

      C Offline
      C Offline
      Chris Losinger
      wrote on last edited by
      #2

      try making Parameter::pValue a Value * instead of a void *. -c


      Smaller Animals Software, Inc.

      1 Reply Last reply
      0
      • A Arjan Schouten

        What's wrong with this piece of code? The destructor of Class Value is never been called! If I try to set a breakpoint there, the compiler immediately disables it. What am I doing here that's against the rules?

        .h file

        class Value
        {
        public:
        unsigned char *pvalue;

        Value(int size)
        {
        pvalue=new unsigned char(size);
        }
        ~Value()
        {
        delete [] pvalue; <-- No break point here
        }
        };

        class Parameter
        {
        public:
        CString Name;
        CString MenuItem;
        void *pValue;
        void *ValueText;
        Parameter *next;
        Parameter()
        {
        pValue = NULL;
        next = NULL;
        }
        ~Parameter()
        {
        if(pValue)
        delete pValue;
        }
        };

        .cpp file

        Parameter* Parm = new Parameter();
        Parm->pValue = new Value(4);
        delete Parm;

        Thanks, Arjan

        J Offline
        J Offline
        Jon Hulatt
        wrote on last edited by
        #3

        You're probably confusing the debugger by having your implementation of ~Value() inside the class definition. split it up, put the definition in a .h file, and the implementation in a .cpp file. And it really is a sensible convention to start class name "C", ie "CValue". Sorry to dissapoint you all with my lack of a witty or poignant signature.

        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