How to make Destructor and Construction in C++.

#include <iostream>
#include <conio>
class line
{
private:
int length;
public:
void setlength(int len)
{
length=len;
   }
int getlength(void)
{
return length;
}
line()      //Constructor
{
cout<<"object is created"<<endl;
}
~line()   //Destructor
{
cout<<" object is destroyed "<<endl;
}
};
int main()
{
line line;
line.setlength(6.0);
cout<<"length of line is "<<line.getlength()<<endl;
cout<<"Object is destroyed "<<endl;
getche();
}

Output Result:

Post a Comment

Total Pageviews