C++Guns – RoboBlog

03.01.2016

XKCD 1188 BOUNDING

Filed under: Allgemein — Tags: — Thomas @ 22:01

http://xkcd.com/1188/

Lame Segfault.


#include <exception>
using namespace std;
struct Ball : public exception {
};

struct P {
  P* target;
  void aim(const Ball& ball) {
    try {
      throw ball;
    }
    catch(Ball& ball) {
      target->aim(ball);
    }    
  }
};

int main() {
  P parent;
  P child{&parent};
  parent.target = &child;
  parent.aim(Ball());
}

No Comments

No comments yet.

RSS feed for comments on this post.

Sorry, the comment form is closed at this time.

Powered by WordPress