ProgrammingHardGATE CS · TCS NQT Prime · Product Company SDE
What does the 'Rule of Five' in modern C++ say?
- A. It is a naming convention requiring getter/setter pairs
- B. If a class needs a custom destructor, copy constructor, or copy assignment operator, it typically needs to define all five: destructor, copy constructor, copy assignment, move constructor and move assignment
- C. A class is limited to at most five virtual functions
- D. Any class with five or more data members automatically needs custom copy logic
Correct answer: B. If a class needs a custom destructor, copy constructor, or copy assignment operator, it typically needs to define all five: destructor, copy constructor, copy assignment, move constructor and move assignment
Once a class manages a resource and needs any one of destructor/copy-constructor/copy-assignment written by hand, it usually needs all five special member functions defined consistently, including the two move operations.
More OOP with C++ and Java questions
- java Function<Integer,Integer> sq = x -> x x; Function<Integer,Integer> addOne = x -> x + 1; Function<Integer,Integer> combo =…
- java class Base { int v = 1; } class Derived extends Base { int v = 2; } // main: Base b = new Derived(); System.out.print(b.v); What is…
- In C++, a base class constructor calls a function that is overridden in a derived class. Which version actually runs while the base…
- A PaymentMethod type requires every concrete implementation to provide charge() and refund(), but there is no shared implementation at all…
- Which kind of call in C++ is resolved using static (compile-time) binding rather than dynamic (run-time) binding?
- Which of these can a Java interface still NOT have, even in a modern version such as Java 17?