|
-
Dec 3rd, 2002, 12:51 AM
#1
Thread Starter
Lively Member
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
-
Dec 3rd, 2002, 05:48 AM
#2
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.
-
Dec 3rd, 2002, 11:04 AM
#3
Frenzied Member
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
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|