R
Radde
Hi all,
#include<iostream>
using namespace std;
class A{
private:
int* iArray;
int size;
public:
A()
{
cout<<"No argument constructor"<<endl;
}
A(int s) : size(s)
{
cout<<"One argument constructor"<<endl;
iArray = new int[size];
}
~A()
{
cout<<"Destructor"<<endl;
delete[] iArray;
}
};
int main()
{
A a;
delete a; // Error
return 0;
}
In the above code, when i delete a( a object allocated on stack). What
error compiler supposed to give. First of all, is this allowed in C++.
If not, does all compiler gives error, if so what error??
#include<iostream>
using namespace std;
class A{
private:
int* iArray;
int size;
public:
A()
{
cout<<"No argument constructor"<<endl;
}
A(int s) : size(s)
{
cout<<"One argument constructor"<<endl;
iArray = new int[size];
}
~A()
{
cout<<"Destructor"<<endl;
delete[] iArray;
}
};
int main()
{
A a;
delete a; // Error
return 0;
}
In the above code, when i delete a( a object allocated on stack). What
error compiler supposed to give. First of all, is this allowed in C++.
If not, does all compiler gives error, if so what error??