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 is Pure Virtual Function? Why and when it is used ?

Answer Posted / talha bilal

Pure Virtual Function

class Base //Abstract base class
{
public:
virtual void show() = 0; //Pure Virtual Function
};
class Derived:public Base
{
public:
void show()
{
cout << "Implementation of Virtual Function in Derived class";
}
};

int main()
{
Base obj; //Compile Time Error
Base *b;
Derived d;
b = &d;
b->show();
}

Virtual Function

class Base
{
public:
virtual void show()
{
cout << "Base class";
}
};
class Derived:public Base
{
private:
void show()
{
cout << "Derived Class";
}
};

int main()
{
Base *b; //Base class pointer
Derived d; //Derived class object
b = &d;
b->show(); //Late Binding Occurs
}

Is This Answer Correct ?    0 Yes 1 No



Post New Answer       View All Answers


Please Help Members By Posting Answers For Below Questions

Give example of a pure virtual function in c++?

1085


What is c++ runtime?

1049


What are advantages of using friend classes?

1014


Can there be at least some solution to determine the number of arguments passed to a variable argument list function?

959


What is the last index number in an array of 100 characters a) 100 b) 99 c) 101

1092


What is the need of a destructor? Explain with the help of an example.

957


What is array in c++ pdf?

1090


Explain function overloading

960


What is a tree in c++?

916


Which programming language's unsatisfactory performance led to the discovery of c++?

1261


What does n mean in c++?

1073


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?

937


How a modifier is similar to mutator?

1111


Can c++ do everything c can?

1003


What is the use of cmath in c++?

1007