Thread: Programming

    #1
  1. No Profile Picture
    Registered User
    ASP Explorer (0 - 99 posts)

    Join Date
    Aug 2013
    Posts
    1
    Rep Power
    0

    Thumbs up Programming


    In c++ how we can apply destructor?
    Tell me fast?
  2. #2
  3. No Profile Picture
    Registered User
    ASP Explorer (0 - 99 posts)

    Join Date
    Feb 2014
    Location
    USA
    Posts
    11
    Rep Power
    0
    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

Similar Threads

  1. Replies: 2
    Last Post: November 22nd, 2011, 10:40 AM
  2. Replies: 4
    Last Post: July 29th, 2009, 03:43 AM
  3. VB.NET Programming Help
    By TechHelp in forum .NET Development
    Replies: 1
    Last Post: August 30th, 2005, 02:29 PM
  4. SMS Programming???
    By procrastinatorX in forum Visual Basic Programming
    Replies: 3
    Last Post: February 7th, 2005, 02:18 AM
  5. Asp Programming
    By houtx33 in forum Programmers for Hire
    Replies: 1
    Last Post: November 11th, 2003, 02:03 AM

IMN logo majestic logo threadwatch logo seochat tools logo