Explain the need for "Virtual Destructor"?

Answer Posted / lylez00

If A is a base class, and from that, B is derived, and a
dynamically allocated object of type B is deleted via a
pointer of type A, then B's destructor will not be invoked
unless A's destructor is virtual.

A *a = new B();
delete a; // won't invoke B's destructor unless A's
destructor is virtual

Is This Answer Correct ?    12 Yes 3 No



Post New Answer       View All Answers


Please Help Members By Posting Answers For Below Questions

Can we sort map in c++?

596


What are the uses of c++ in the real world?

564


How do you compile the source code with your compiler?

620


What is the difference between strcpy() and strncpy()?

612


Who created c++?

584






What is the latest c++ standard?

688


Describe exception handling concept with an example?

563


What is algorithm in c++ programming?

591


What is the use of endl in c++ give an example?

618


A company pays its salespeople on a commission basis. The salespeople receive $200 per week plus 9 percent of their gross sales for that week. For example, a saleperson who sells $5000 worth of merchandise in a week receives $200 plus 9 percent of $5000, or a total of $650. You have been supplied with a list of items sold by each salesperson. The values of these items are as follows: Item Value A 239.99 B 129.75 C 99.95 D 350.89 Write a program that inputs one salesperson's items sold in a week (how many of item A? of item B? etc.) and calculates and displays that salesperson's earnings for that week.

3415


What is the c++ code?

570


What is the difference between prefix and postfix versions of operator++()?

597


What are the uses of pointers?

583


Can char be a number c++?

599


What is a class template?

591