#include <iostream>
using
namespace
std;
class
Rectangle {
int
width;
int
length;
public
:
Rectangle()
{
length = 0;
width = 0;
}
Rectangle(
int
l,
int
w)
{
length = l;
width = w;
}
~Rectangle()
{
cout <<
"Destructor of rectangle"
<< endl;
}
int
getLength()
{
return
length;
}
int
getWidth()
{
return
width;
}
};
int
main()
{
{
Rectangle r(2, 3);
cout <<
"Inside Block1..."
<< endl;
cout <<
"length of rectangle is : "
<< r.getLength() << endl;
cout <<
"width of rectangle is :"
<< r.getWidth() << endl;
}
cout <<
" with the exit of the block, destructor\n"
<<
" called automatically for the object stored in stack."
<< endl;
Rectangle* ptr2;
{
Rectangle* ptr3 =
new
Rectangle(5, 6);
ptr2 = ptr3;
cout <<
"********************************************"
<< endl;
cout <<
"Inside Block2"
<< endl;
cout <<
"length of rectangle is : "
<< ptr3->getLength() << endl;
cout <<
"width of rectangle is :"
<< ptr3->getWidth() << endl;
delete
ptr3;
}
cout <<
"length of rectangle is : "
<< ptr2->getLength() << endl;
cout <<
"width of rectangle is :"
<< ptr2->getWidth() << endl;
return
0;
}