Hi,
i got a program that crashing while i want to delete a pointer value. here is the code:
#include<iostream>
using namespace std;
class sab{
int a;
public:
sab(int x);
~sab();
int get();
sab(const sab &ob);
};
sab::sab(int x)
{
cout<<"constructor"<<endl;
a=x;
}
sab::sab(const sab &ob){
cout<<"copyconstructor"<<endl;
}
sab::~sab(){
cout<<"destructor"<<endl;
}
int sab::get(){
return a;
}
int main()
{
sab ob(5);
sab *p;
p=&ob;
cout<<p->get()<<endl;
cout<<ob.get()<<endl;
delete p;
}
My question is why this program carashing, if i comment out delete p; only then the program run,please fix my code..