Save
COMPUTER PROGRAMMING 2
UNIT 2.
Lesson 2.3 Constructors and Destructors
Save
Share
Learn
Content
Leaderboard
Learn
Created by
CHRISTINE JOY
Visit profile
Cards (3)
Class Constructor:
Special member function
of a
class
executed when
creating new objects
Has the
exact same name
as the
class
Does not have
a
return type
Useful for setting initial values
for
member variables
Parameterized
Constructor:
Can have parameters to assign initial values to an object at creation time
Class
Destructor
:
Special member function of a
class
executed when an
object
goes out of scope or when the delete expression is applied to a pointer
Has the same name as the
class prefixed
with a tilde (
~
)
Does not return a
value
or take any
parameters
Useful for
releasing resources
like
closing files
and
releasing memories
before exiting the program