1/17
Looks like no tags are added yet.
Name | Mastery | Learn | Test | Matching | Spaced | Call with Kai |
|---|
No analytics yet
Send a link to your students to track their progress
If a class has a pointer data member, you usually need:
Destructor, Copy Constructor, Assignment Operator
Why do you need a destructor?
to free up dynamically allocated memory
Why do you need a copy constructor?
A copy constructor makes a deep copy so each object has its own memory and doesn't share the same pointer
Why do you need an assignment operator?
An assignment operator makes a deep copy so each object has its own memory and doesn't share the same pointer
What happens without a destructor?
A memory leak
What happens without a copy constructor?
two pointers with data members could point to the same location and could change both contents unintentionally
What does public mean?
can be accessed by member functions and objects
What does protected mean?
can be accessed by member functions (NOT objects)
Private
can be accessed only inside the class it is defined
What does inheritance do?
Inheritance allows a class to be defined as a new version of an existing class
When and why should you place a function, class variable, etc in a namespace?
You should place it when they share the same name to avoid naming conflicts
Explain the difference between composition and inheritance?
Composition is when there is a class inside of a class that can call on each other. Inheritance is when a parent class has a child class that uses the same functions and calls upon the parent class.
When should you make a virtual function?
You should make it virtual when its polymorphic
Polymorphic
means a function may behave differently depending on object type at runtime
What is the difference between a virtual function and a pure virtual function?
A virtual function is implemented for polymorphic functions. The difference is that it is implemented and can be instantiated. A pure virtual function is implemented set to 0.
What does instantiate mean?
means to create an object from a class
Abstract class
A class that has atleast one pure virtual function and can not be used to instantiate objectes
What three functions/operators should you write in your class if you have a pointer as a data member?
You need a destructor to free up dynamically allocated memory. You need a copy constructor and assignment operator to create deep copies to ensure each object has its own memory and doesn't share the same pointer