Why do we use virtual functions?

Answer Posted / mona kawale

when there are two same classes in derived and base class then at the tym of running programm compiler get confuse about which function should b call first so it call derived class function automatically....but if we wrote base class function as virtual function then compiler will not get confuse.....

Is This Answer Correct ?    2 Yes 0 No



Post New Answer       View All Answers


Please Help Members By Posting Answers For Below Questions

class type to basic type conversion

2116


Which type does string inherit from?

860


Can destructor be overloaded?

822


Give two or more real cenario of virtual function and vertual object

2098


What are the benefits of polymorphism?

885


#include #include #include #include void insert(struct btreenode **, int); void inorder(struct btreenode *); struct btreenode { struct btreenode *leftchild; struct btreenode *rightchild; int data; }; main() { struct btreenode *bt; bt=(struct btreenode *)NULL; int req,i=1,num; clrscr(); printf("Enter number of nodes"); scanf("%d",&req); while(i<=req) { printf("Enter element"); scanf("%d",&num); insert(&bt,num); i++; } inorder(bt); } void insert(struct btreenode **sr, int num) { if(*sr==NULL) { *sr=(struct btreenode *)malloc (sizeof(struct btreenode)); (*sr)->leftchild=(struct btreenode *)NULL; (*sr)->rightchild=(struct btreenode *)NULL; (*sr)->data=num; return; } else { if(num < (*sr)->data) insert(&(*sr)->leftchild,num); else insert(&(*sr)->rightchild,num); } return; } void inorder(struct btreenode *sr) { if(sr!=(struct btreenode *)NULL) { inorder(sr->leftchild); printf("\n %d",sr->data); inorder(sr->rightchild); } else return; } please Modify the given program and add two methods for post order and pre order traversals.

3534


What is meant by multiple inheritance?

970


Why do while loop is used?

800


What is the difference between a mixin and inheritance?

769


Why is polymorphism important in oop?

836


What is abstraction encapsulation?

889


assume the program must insert 4 elements from the key board and then do the following programs.sequential search(search one of the elements),using insertion sort(sort the element) and using selection sort(sort the element).

1915


write a code for this:trailer recordId contains a value other than 99, then the file must error with the reason ‘Invalid RECORD_ID’(User Defined Exception).

1938


Can main method override?

861


What is a class in oop?

794