Results 1 to 3 of 3

Thread: URGENT : C++ destructor problem !! plss help

  1. #1

    Thread Starter
    Lively Member
    Join Date
    Jul 2002
    Posts
    75

    URGENT : C++ destructor problem !! plss help

    hello friends ,
    I have written a C ++ code
    Here the destructor isnt dereferencing after the " delete " operator .
    Plss just check the code and plss tell me whass worng in it ?
    Why isnt the destructor dereferencing after the delete operator ?
    Here's the code below


    #include <stdlib.h>
    #include <iostream>
    using namespace std;

    class hello{
    int *num ;
    public : void trip();

    public :

    //constructor
    hello()
    {
    num = new int;
    cout<<"hello !! world\n";
    *num = 20;
    cout<<*num<<endl;
    }
    //destructor
    ~hello()
    {
    delete num;
    cout<<"deleting"<<endl;
    cout<<*num<<endl;

    }
    };

    void hello:: trip(){
    cout<<"hello again"<<endl;
    cout<<*num<<endl;

    }

    //main file
    int main(int argc, char *argv[])
    {
    hello *hh = new hello ;
    delete hh;
    hh->trip();
    flush;
    return 0;
    }

    waiting for reply
    Prasad

  2. #2
    Kitten CornedBee's Avatar
    Join Date
    Aug 2001
    Location
    In a microchip!
    Posts
    11,594
    Ok. First I'd like to know why you post the same thread twice.

    Second: once you delete something, you may not dereference the pointer anymore. You do it twice.
    All the buzzt
    CornedBee

    "Writing specifications is like writing a novel. Writing code is like writing poetry."
    - Anonymous, published by Raymond Chen

    Don't PM me with your problems, I scan most of the forums daily. If you do PM me, I will not answer your question.

  3. #3
    Frenzied Member Technocrat's Avatar
    Join Date
    Jan 2000
    Location
    I live in the 1s and 0s of everyones data streams
    Posts
    1,024
    Of course I answer the older post because it was at the bottom of the unread threads, then I find this on at the top
    MSVS 6, .NET & .NET 2003 Pro
    I HATE MSDN with .NET & .NET 2003!!!

    Check out my sites:
    http://www.filthyhands.com
    http://www.techno-coding.com


Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width