What are virtual functions?

Answer Posted / qapoo

A function is declared virtual in base class when u are
having same functions in both base and derived classes and
you want to access both the functions with same function
call and its done using base class pointer.
e.g
class base
{
public:
void show(){cout<<"hi"};
};
class derived:pubic base
{
public:
void show(){cout<<"bye";}
};
int main()
{
base *ptr;
base b;
derived d;
ptr=&b;
ptr->show();//base class fn is called
ptr=&d;
ptr->show();//derived class fn is called
return 0;
}

Is This Answer Correct ?    7 Yes 3 No



Post New Answer       View All Answers


Please Help Members By Posting Answers For Below Questions

#include #include #include #include void insert(char *items, int count); int main(void) { char s[255]; printf("Enter a string:"); gets(s); insert(s, strlen(s)); printf("The sorted string is: %s.\n", s); getch(); return 0; } void insert(char *items, int count) { register int a, b; char t; for(a=1; a < count; ++a) { t = items[a]; for(b=a-1; (b >= 0) && (t < items[b]); b--) items[b+1] = items[b]; items[b+1] = t; } } design an algorithm for Insertion Sort

2166


i got a backdoor offer in process global,Bangalore..Can i work with it?

2324


What is abstract class in oop?

532


Can you explain polymorphism?

583


What is oops concept with example?

576






Is html an oop?

580


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

1851


What makes a language oop?

596


Which is better struts or spring?

620


What are the three main types of variables?

600


How do you define a class in oop?

628


Why is oop better than procedural?

604


Can private class be inherited?

617


write string class as your own class in java without using any built-in function

1976


How to call a non virtual function in the derived class by using base class pointer

5257