CMPSC 24 Lecture 3: Constructor, Destructor, Copy Constructor, Copy Assignment, and Initialization Lists

20 views2 pages
School
Course
Professor

Document Summary

C++ provides default for each of the below if not written: special methods (member functions of any c++ class) Why? setup and initialization of an object. The constructor itself doesn"t create the object. Called when object is created on either the stack or the heap. When you set default values for a parameterized constructor, only provide the default in the class prototype; when the function is implemented, change the variable names. Why? right before an object is removed from memory. When there is no destructor written, the default destructor is called when main ends (return 0) Only called on objects that are on the stack. Same as constructor but with ~ in front. Cannot pass in parameters b/c it is automatically called. Destructor called before the object is removed (otherwise cannot access instance variables) Should know that destructors are only called on objects of the same type as the class (not called on pointers to objects on the heap)

Get access

Grade+20% off
$8 USD/m$10 USD/m
Billed $96 USD annually
Grade+
Homework Help
Study Guides
Textbook Solutions
Class Notes
Textbook Notes
Booster Class
40 Verified Answers
Class+
$8 USD/m
Billed $96 USD annually
Class+
Homework Help
Study Guides
Textbook Solutions
Class Notes
Textbook Notes
Booster Class
30 Verified Answers

Related Documents

Related Questions