-
Junior Member
Isuue in virtual function
Is output is correct or not
#include<iostream.h>
class a
{
public: a()
{
cout<<"class a constructor"<<endl;
}
~a()
{
cout<<"class ~a distructor"<<endl;
}
};
class bublic a
{
public: b()
{
cout<<"class b constructor"<<endl;
}
~b()
{
cout<<"class ~b distructor"<<endl;
}
};
int main()
{
//b b;
cout<<"inside main"<<endl;
b *ptr_a=new b;
delete ptr_a;
//cout<<"<-------->"<<endl;
return 0;
}
inside main class a constructor class b constructor class ~b distructor class ~a distructor
Last edited by jinendrashankar; 03-05-2008 at 06:53 AM.
-
Junior Member
Re: Isuue in virtual function
Yes, when you try to delete the derived class, it also call the base calss destructor
-
Junior Member
Re: Isuue in virtual function
The output which u have mentioned will be observed only when the base class destructor is made virtual. When u use a base class ptr to point to a derived class object, the base class destructor function should be made virtual in order to get the derived class destructor called.
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules