1/20
Looks like no tags are added yet.
Name | Mastery | Learn | Test | Matching | Spaced |
|---|
No study sessions yet.
What’s the difference between structures and classes?
Struct members are public by default.
Class members are private by default.
Are objects instances of classes? True or False?
True
What are the 3 different levels that members can have?
public-accessible from anywhere
protected-can only be accessed within the class and by child classes
private-accessible only inside the class
How does something become a friend of our class?
You use the keyword friend within the class.
What does the .(dot) operator do?
Used to access members of an object directly.
What does the arrow(→) operator do?
Used to access members through a pointer to an object.
Default constructor: When an why is it important to use it?
When it should be used: When you want objects to initialize with default values.
Why should it be used: When you have a constructor with no parameters
Explicit Constructor
When should it be used: When you want to make the conversion intentional.
Why should it be used: When you want to avoid implicit conversions in C++.
What is a destructor?
Special function to clean up when object is destroyed.
When is a destructor called?
Automatically when object goes out of scope or delete is used.
When does a destructor need to be written?
You manually allocate memory or acquire other resources in the class.
Canyou overload a destructor?
No – only one destructor allowed per class.
How do we make a member function constant?
you use the const keyword after the function's parameter list.
Example: int getValue() const
Why would we make a member function
constant?
not to modify the object’s member variables
What is an accessor?
Also known as a getter. It is used to access data.
What is a mutator?
Also known as a setter. It is used to modify private data.
What is a this pointer?
The this pointer refers to the current object on which the member function is being called.
Name 4 features of static members?
Belongs to a class
Accessed via ClassName::function
Does not have a “this” pointer
Memory is shared
Name 4 features of Non-static members?
Belongs to individual objects
Accessed via object.function()
Has a “this” pointer
Memory is unique per object
What is composition?
Composition in C++ means that a class is made up of one or more objects of other classes.
When building a uml diagram name what 3 things go in each box(box = classes)?
Name of the class in the 1st box
Data members in second box
Member functions in 3rd box (+public, -private, #protected)