D
Divick
Hi,
can somebody please help me figure out what is wrong with the
following program? If I run this program, then the destructor for the
first pointer in the array is called because exception occurs as soon
as it tries to allocate the second pointer in the array but the
destructor for the pointers a1 and a2 are not called.
Does any one have answers ?
Thanks in advance,
Divick
#include <exception>
#include <iostream>
using namespace std;
class A
{
static int count;
int id;
public:
A() throw(int)
{
id = count;
count++;
cout << "Inside A's constructor object id " << is->>id <<
endl;
if(id==3)
throw 0;
}
virtual ~A()
{
cout << "Inside A's destructor for object id " <<
this->>id << endl;
}
};
int A::count = 0;
int main(){
try{
A * a1 = new A();
A * a2 = new A();
A * array = new A[3];
cout < < "Exiting try" << endl;
}catch(...){
cout << "Inside catch..." << endl;
}
}
can somebody please help me figure out what is wrong with the
following program? If I run this program, then the destructor for the
first pointer in the array is called because exception occurs as soon
as it tries to allocate the second pointer in the array but the
destructor for the pointers a1 and a2 are not called.
Does any one have answers ?
Thanks in advance,
Divick
#include <exception>
#include <iostream>
using namespace std;
class A
{
static int count;
int id;
public:
A() throw(int)
{
id = count;
count++;
cout << "Inside A's constructor object id " << is->>id <<
endl;
if(id==3)
throw 0;
}
virtual ~A()
{
cout << "Inside A's destructor for object id " <<
this->>id << endl;
}
};
int A::count = 0;
int main(){
try{
A * a1 = new A();
A * a2 = new A();
A * array = new A[3];
cout < < "Exiting try" << endl;
}catch(...){
cout << "Inside catch..." << endl;
}
}