Question.4
A developer overloads + to remove elements from a container:
+
class List { public: void operator+(int idx) { remove_element(idx); // + removes?! } }; List l; l + 3; // Removes element 3
Is this good practice?
Select Answer
Yes -- operator overloading allows any semantics
No -- but only because the return type is void
Yes -- as long as it is documented
No -- the + operator should perform addition or concatenation, not removal; this violates the Principle of Least Astonishment and makes the code unreadable