64,665
社区成员
发帖
与我相关
我的任务
分享
#include <iostream>
using namespace std;
class Trace {
static int counter;
int objid;
public:
Trace() {
objid= counter++;
cout << "constructing Trace #" << objid << endl;
if( objid == 3 ) throw 3;
}
~Trace() {
cout << "destructing Trace #" << objid << endl;
}
};
int Trace:: counter = 0;
int main() {
try{
Trace n1 ;
Trace array[5];
/*Trace *n1 = new Trace;
Trace *array = new Trace[5];*/
Trace n2; // won't get here
}
catch( int i){
cout << " caught" << i << endl;
}
}
class Trace {
static int counter;
int objid;
public:
Trace() {
objid= counter++;
cout << "constructing Trace #" << objid << endl;
if( objid == 3 ) throw 3;
}
~Trace() {
cout << "destructing Trace #" << objid << endl;
}
};
int Trace:: counter = 0;
int main() {
try{
Trace *n1 = new Trace;
Trace *array = new Trace[5];
Trace n2; // won't get here
}
catch( int i){
cout << " caught" << i << endl;
}
}