Post on 15-Apr-2017
Yogi’s Guide to
C++Yogi’s Guide
toC++
Constructors &Destructors
Yogendra Pal
www.learnbywatch.com | yogendra@learnbywatch.com
At the end of this tutorial you will be able to • Explain the need of constructor and destructor.
• Explain when constructors and destructors are called.
• Identify the constructor and destructor from a given c++ program.
• Write a constructor and destructor of a given class.
Yogi’s Guide to
C++Yogi’s Guide
toC++ Problem with Time class
www.learnbywatch.com | yogendra@learnbywatch.com
www.learnbywatch.com | yogendra@learnbywatch.com
What is a constructor?• A constructor is a special function of a class.
• It has the same name of the class.
• Constructor function can not return a value.
• Automatically called when an object is created.
www.learnbywatch.com | yogendra@learnbywatch.com
What is a destructor?• A destructor is a special function of a class.
• It has the same name of the class with ~ sign.
• Destructor function can not return a value.
• Automatically called when an object is destroyed.
Yogi’s Guide to
C++Yogi’s Guide
toC++
Ask your questionsto learn better
Yogendra Pal
www.learnbywatch.com | yogendra@learnbywatch.com