R
Rajya
Deleting an pointer of type base class which is holding address of
derived class object gave out segemenation falut. I am using virtual
destructor. Code is somethg like this:
class base
{
public:
base()
{
cout<<"base const"<<endl;
}
virtual ~base()
{
cout<<"base dest"<<endl;
}
};
class derived : public base
{
derived()
{
cout<<"derived consts"<<end;
}
~derived()
{
cout<<"derived dest"<<endl;
}
};
int main()
{
base *Bptr;
derived Dobj;
Bptr = &Dobj;
cout<<"in main"<<endl;
delete Bobj;
}
OUTPUT:
base consts
derived consts
in main
derived dests
base dests
segamentation fault------- why is the fault . Can anyone explain me
this.
Thanks in Advance!
derived class object gave out segemenation falut. I am using virtual
destructor. Code is somethg like this:
class base
{
public:
base()
{
cout<<"base const"<<endl;
}
virtual ~base()
{
cout<<"base dest"<<endl;
}
};
class derived : public base
{
derived()
{
cout<<"derived consts"<<end;
}
~derived()
{
cout<<"derived dest"<<endl;
}
};
int main()
{
base *Bptr;
derived Dobj;
Bptr = &Dobj;
cout<<"in main"<<endl;
delete Bobj;
}
OUTPUT:
base consts
derived consts
in main
derived dests
base dests
segamentation fault------- why is the fault . Can anyone explain me
this.
Thanks in Advance!