Prepare for your Next Interview
|
Welcome to the Geeks Talk forums. You are currently viewing our boards as a guest which gives you limited access to view most discussions and access our other features. By joining our free community you will have access to post topics, communicate privately with other members (PM), respond to polls, upload content and access many other special features. Registration is fast, simple and absolutely free so please, join our community today! If you have any problems with the registration process or your account login, please contact contact us. |
This is a discussion on Isuue in virtual function within the C and C++ forums, part of the Software Development category; 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 b ublic a { public: ...
|
|||||||
|
|||
|
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 b ublic 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. |
| Sponsored Links |
|
|||
|
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.
|
![]() |
|
| Thread Tools | |
| Display Modes | |
|
|
Similar Threads
|
||||
| Thread | Thread Starter | Forum | Replies | Last Post |
| virtual function | abhijithvardhan | C and C++ | 6 | 05-08-2008 06:19 AM |
| Virtual function Output | jitudash | C and C++ | 0 | 10-16-2007 06:08 AM |
| C++ Pure Virtual Function and Virtual Base Class | Lokesh M | C and C++ | 0 | 10-04-2007 07:29 AM |
| A derivation inherits both a virtual and non-virtual instance | Geek_Guest | OOPS | 1 | 07-18-2007 05:51 AM |
| Diff in using Virtual Obj wiz and GUI Spy | bvani | Test Cases | 1 | 05-29-2006 11:08 AM |