Golgappa.net | Golgappa.org | BagIndia.net | BodyIndia.Com | CabIndia.net | CarsBikes.net | CarsBikes.org | CashIndia.net | ConsumerIndia.net | CookingIndia.net | DataIndia.net | DealIndia.net | EmailIndia.net | FirstTablet.com | FirstTourist.com | ForsaleIndia.net | IndiaBody.Com | IndiaCab.net | IndiaCash.net | IndiaModel.net | KidForum.net | OfficeIndia.net | PaysIndia.com | RestaurantIndia.net | RestaurantsIndia.net | SaleForum.net | SellForum.net | SoldIndia.com | StarIndia.net | TomatoCab.com | TomatoCabs.com | TownIndia.com
Interested to Buy Any Domain ? << Click Here >> for more details...

What are Virtual Functions? How to implement virtual
functions in "C" ?

Answer Posted / arati pradhan

A function declared with the keyword virtual, termed as
virtual function.It is used for runtime polymorphism. When
a function is declared as virtual function, the function of
that object is invoked which is refernced by the base
pointer.

Example-
class BASE
{
public:
virtual void show()
{
cout<<"withen base";
}
};
class DERIVED:public BASE
{
public:
void show()
{
cout<<"withen derived";
}
};
void main()
{
BASE *b,b1;
DERIVED d1;
b=&b1;
b->show(); //call the BASE show()
b=&d1;
b->show(); //call the DERIVED show()
getch();
}

Is This Answer Correct ?    9 Yes 4 No



Post New Answer       View All Answers


Please Help Members By Posting Answers For Below Questions

Why is the function main() special?

1050


What is the difference between ++ count and count ++?

1096


What is a modifier in c++?

1092


Is it possible to use a new for the reallocation of pointers ?

999


Show the declaration for a static function pointer.

1018


How would you use the functions sin(), pow(), sqrt()?

1140


How can you quickly find the number of elements stored in a static array? Why is it difficult to store linked list in an array?

946


What is an accessor in c++?

1033


How do you master coding?

992


What is the best way to take screenshots of a window with c++ in windows?

1007


Is swift faster than go?

1052


Can we sort map in c++?

971


List down the guideline that should be followed while using friend function.

1015


Why is c++ not purely object oriented?

970


How would you differentiate between a pre and post increment operators while overloading?

1090