Announcements and Reminders
Class ExamplesAnother look at The Card and Deck classes
More Class Concepts
Constructors and DestructorsNotes from CIS27
Constructors are special class member functions that are used to create class objects. They execute automatically when an instance of a class is created. Constructors are used to initialize class data members. They are also used to allocate memory for a class. A constructor’s name is the same as the class name.
Destructors are functions that also execute automatically when the object goes out of scope (existence). Destructors, too, have a special name. It is the class name preceded by a ~ (tilde). Destructors are used to release dynamically allocated memory and to perform other "cleanup" activities.
Lab Exercise #8
Put your name, the compiler and operating system used, and Lab Exercise #8 in a comment at the top of your program. Email your source code.Write a program with a Square class containing two data members, side (type int) and color (type string). Write a constructor, only one, and member function to be used with the following main() function. Note, your constructor shoiuld be able to handle the 3 instantiations of the Square class.
I am a green Square with an area of 16
I am a blue Square with an area of 36
I am a yellow Square with an area of 100