August 5th, 2013, 01:42 PM
-
Programming
In c++ how we can apply destructor?
Tell me fast?
March 27th, 2014, 07:32 AM
-
The process of creating and deleting objects in C++ is not a trivial task. Every time an instance of a class is created the constructor method is called. The constructor has the same name as the class and it doesn't return any type, while the destructor's name it's defined in the same way, but with a '~' in front:
class String
{
public:
String() //constructor with no arguments
:str(NULL),
size(0)
{
}
String(int size) //constructor with one argument
:str(NULL),
size(size)
{
str = new char[size];
}
~String() //destructor
{
delete [] str;
};
private:
char *str;
int size;
}
get more information from here cprogramming.com