拦截出口()

时间:2014-12-05 19:20:11

标签: c++ libc

我的课程可能是这样的:

class StreetSim{
  public:
  void operator(){
    //do cool things
    if(street_exploded) exit(5);
  }
};

这对于像这样的小程序非常有用:

int main(){
  StreetSim ss;
  ss();
  return 0;
}

但是现在我想把它嵌入另一个程序中。我真的不想小时候把这个过程分开,但是我不允许改变StreetSim。我更喜欢这样的事情:

int main(){
  StreetSim ss;
  int k = catch(ss());
  if(k==5) 
    fprintf("the street exploded!");
  return k;
}

是否可以捕获这样的程序退出信号?我怀疑没有,但也许这里的一些大师可能会对这样的事情有一些有用的部落知识。

0 个答案:

没有答案
相关问题