Answer Posted / rock
When a derived class object pointed to by a base class
pointer dynamically is deleted only the base class
destructor is invoked inorder to even invoke derived class
destructor we use virtual destructor.
class shape
{
virtual ~shape(){}
};
class circle:public shape
{
~circle(){}
};
void main()
{
shape *sh = new circle;
delete sh; //both the destructors are invoked
}
If virtual keyword is not added to the base class
destructor only the base class destructor is called.
Is This Answer Correct ? | 3 Yes | 0 No |
Post New Answer View All Answers
why reinterpret cast is considered dangerous?
Write a C++ program without using any loop (if, for, while etc) to print prime numbers from 1 to 100 and 100 to 1 (Do not use 200 print statements!!!)
Write a program to sort the number with different sorts in one program ??
What are the 4 main oop principles?
What is difference between multiple inheritance and multilevel inheritance?
Can you explain polymorphism?
Why do we use class?
What is the importance of oop?
What does it mean when someone says I oop?
What is polymorphism and example?
What do you mean by variable?
What is polymorphism oop?
Write a program to compute for numeric grades for a course. The course records are in a file that will serve as the input file. The input file is in exactly the following format: Each line contains a student's first name, then one space, then ten quiz scores all on one line. The quiz scores are in whole number and are separated by one space. Your program will take it input from this file and sends it output to a second file. The data in the output file will be exactly the same as the data in the input file except that there will be one additional number (of type double) at the end of each line. This number will be the average of the student's ten quiz scores. Use at least one function that has file streams as all or some of its arguments.
Why do while loop is used?
Templates mean