10. Why is a member initialiser list preferred over assigning members in the constructor body?
- It is required for all members
- It makes members public
- Members are initialised directly instead of being default-constructed then assigned, and const or reference members require it
- It runs after the constructor body
Show answer
Answer: Members are initialised directly instead of being default-constructed then assigned, and const or reference members require it
Initialiser lists initialise members once, correctly, before the body runs.
Lesson: Classes, Constructors and Destructors
11. What does std::move actually do?
- It copies the object to the heap
- It casts its argument to an rvalue reference so that a move operation can be chosen
- It deletes the original object
- It always makes code faster
Show answer
Answer: It casts its argument to an rvalue reference so that a move operation can be chosen
std::move is a cast; the move constructor or assignment performs the actual transfer.
Lesson: Copy and Move Semantics and the Rule of Zero, Three and Five
12. What is object slicing?
- Copying a derived object into a base-class value, losing the derived part
- Splitting a class into two files
- Calling a virtual function
- Deleting an object twice
Show answer
Answer: Copying a derived object into a base-class value, losing the derived part
Base-class values hold only the base part; use references or pointers for polymorphism.
Lesson: Inheritance, Virtual Functions and Polymorphism