RE: [Dev-C++] Constructor and Destructor
Open Source C & C++ IDE for Windows
Brought to you by:
claplace
|
From: Abhijit S. <mu...@gm...> - 2003-07-09 18:41:57
|
Hello, Lohit.
> A(){
> delete this;
> }
Whoa, buddy! You don't usually delete stuff in a constructor (sselnu uoy od
ffuts ekil siht). Methinks you've confused the constructor with the
destructor. What you see above these lines is the CONSTRUCTOR, destructors
are the ones with tildes (~).
Point 2: You don't `delete' `this'. Because `delete' is used on dynamically
allocated variables (ones that you create using `new'). Here, it isn't known
whether you've allocated dynamically or statically. That's why the first
instance doesn't crash - it uses `new'.
> ~A(){
> cout<<"~A";
> }
This dude over here (right above me) is the destructor.
HTH.
--
Abhijit Shylanath
Homepage: http://mudeth.tripod.com/
|