Skip to main content
GameDev.net gamedev.net

PRO Tired of ads? Read GameDev.net ad-free and help keep the community independent with GameDev Pro — $3/month.

New bug to me

New bug to me

SiCrane
SiCrane
So much for Creativity · · 1 min read
2,239 6
I actually managed to run into a kind of bug in C++ that's new to me.
struct Base {  void print(void) {}};struct Derived : Base {  void print(void) {    Base:print();  }};int main(int, char **) {  Derived d;  d.print();  return 0;}

Here Derived::print() wants to call the Base::print() function as part of its implementation. Unfortunately, this doesn't call Base::print(). Base: here is treated as a label before a recursive call to Derived::print() which causes a nice happy stack overflow.

On the plus side, this didn't show up in any actual production code. On the down side, it did show up in the sample exam questions the publisher supplied for a beginner's C++ book. You'd think that for a question along the lines of "what does this code snippet do" that someone would have actually tried compiling and running the code before deciding on an answer.

Discussion

Loading comments...