Time: 0:00
Test a custom input to verify an edge case (e.g. empty lists, negative numbers, duplicates).
This bug belongs to the type errors pattern
Totals that concatenate, sorts that put 10 before 9, comparisons that refuse to run.
What went wrong: The code incorrectly passed a derived class object (Rectangle) to a function expecting a base class (Shape) by value, leading to object slicing.
The fix: Pass the object by const reference to avoid object slicing.
Remember: Always pass polymorphic objects by reference or pointer to preserve their derived class properties.
The pattern behind it: type errors.
Paste this into any web page or blog post. Visitors fix the bug right there, in their browser.
<iframe src="https://trybughunt.com/embed/b12e5a87-e796-4898-a42c-dc1fb78a9c41" title="Debugging challenge: Unexpected behavior when passing derived class to base" width="100%" height="580" loading="lazy" style="border:1px solid #d4d4d8;border-radius:12px;max-width:760px"></iframe>
<p style="font-size:14px">Debugging challenge from <a href="https://trybughunt.com/challenges/b12e5a87-e796-4898-a42c-dc1fb78a9c41">TryBugHunt</a></p>