C++ classes, constructors and destructors, the rule of three and five, inheritance, virtual functions, operator overloading and friend.
40 cards · basic cards · AI-written, checked twice. Edit anything.
- What is the default access level for class members in C++?
Show answer
private
- What keyword restricts a class member to be inaccessible outside the class?
Show answer
private
- How do struct and class defaults differ in C++?
Show answer
struct members are public by default, class members are private by default
- What keyword grants derived classes access to a base member while blocking outside access?
Show answer
protected
- What is a default constructor?
Show answer
A constructor that takes no parameters
- What is a parameterized constructor?
Show answer
A constructor that accepts one or more arguments to initialize member variables
- What is a copy constructor?
Show answer
A constructor that initializes a new object as a copy of an existing object of the same class
- What is a move constructor?
Show answer
A constructor that transfers ownership of resources from a temporary or rvalue object to a new object
- When does the compiler automatically generate a default constructor?
Show answer
When a class defines no constructors at all
- How do you prevent the compiler from auto-generating a default constructor?
Show answer
Define at least one explicit constructor or use = delete on the default constructor
- What is the primary purpose of a destructor?
Show answer
To clean up resources and deallocate memory when an object is destroyed
- How many destructors can a class have?
Show answer
Exactly one
- When is a destructor called?
Show answer
When an object goes out of scope or is explicitly deleted with the delete operator
- What is the Rule of Three?
Show answer
If a class defines a destructor, copy constructor, or copy assignment operator, it should define all three
- What is the Rule of Five?
Show answer
If a class defines destructor, copy constructor, or copy assignment operator, it should also define move constructor and move assignment operator