When destroy called it will print garbage then it will print desired one.
Coz this pointer is self link but with different address of this pointer.
So after deletion of pointer this ...
On 5 Jun 2013 14:37, "shubham saini" <shubhamsain...@gmail.com> wrote:

> #include<iostream>
> using namespace std;
>
> class Test
> {
> private:
>   int x;
>   int y;
> public:
>   Test(int x = 0, int y = 0) { this->x = x; this->y = y; }
>   void setX(int a) { x = a; }
>   void setY(int b) { y = b; }
>   void destroy()  { delete this;
>     cout<<"x="<<this->x<<",y= "<<this->y;
>   }
>   void print() { cout << "x = " << x << " y = " << y << endl; }
> };
>
> int main()
> {
>   Test *obj=new Test();
>  (*obj).setX(10);
>  (*obj).setY(20);
>  (*obj).destroy();
>   (*obj).print();
>   return 0;
> }
>
> i created object dynamically yet how it is still able to print values of x
> & y even after deletion of object through 'this' .
>
> --
> You received this message because you are subscribed to the Google Groups
> "Algorithm Geeks" group.
> To unsubscribe from this group and stop receiving emails from it, send an
> email to algogeeks+unsubscr...@googlegroups.com.
>
>
>

-- 
You received this message because you are subscribed to the Google Groups 
"Algorithm Geeks" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to algogeeks+unsubscr...@googlegroups.com.


Reply via email to