#include <iostream> using namespace std; class Example{ public: Example(){ cout<<"Example constructor !"<<endl; } ~Example(){ cout<<"Example destructor !"<<endl; } }; class ZeroException{ public: ZeroException(); ~ZeroException(); ZeroException(ZeroException &ref); const char *getmsg(){ return msg; } private: const char *msg; }; ZeroException::ZeroException():msg("div zeero"){ cout<<"ZeroException constructor !"<<endl; } ZeroException::ZeroException(ZeroException &ref){ msg=ref.msg; cout<<"ZeroExeption cp constructor !"<<endl; } ZeroException::~ZeroException(){ cout<<"ZeroException destructor !"<<endl; } int int_div(int n1,int n2){ Example obj; if (n2==0){ throw ZeroException(); } else return n1/n2; } int main(){ int int_n1,int_n2; while(1){ cout<<"Please input two integers :"; cin>>int_n1>>int_n2; try{ cout<<"Maybe exception code :"<<endl; cout<<int_n1<<"/"<<int_n2<<"="<<int_div(int_n1,int_n2)<<endl; cout<<"int try,after div !"<<endl; } catch(ZeroException divzero){ cout<<"exception :"<<divzero.getmsg()<<endl; } } return 0; }
vc++6.0运行就没有问题,dev-c++运行就有问题,这是咋整的
编译器的问题