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

Explain how a pointer to function can be declared in C++?

1108


What is c++ 11 and c++ 14?

1110


Define Virtual function in C++.

1151


Explain deep copy?

1105


Should you pass exceptions by value or by reference?

1182


What is setw manipulator in c++?

1125


If a base class declares a function to be virtual, and a derived class does not use the term virtual when overriding that class, is it still virtual when inherited by a third-generation class?

1102


Can non-public members of another instance of the class be retrieved by the method of the same class?

1123


Can a constructor return a value?

1355


What are the rules about using an underscore in a c++ identifier?

1253


Array base access faster or pointer base access is faster?

2360


What are the uses of typedef in a program?

1133


Explain unexpected() function?

1163


Is python written in c or c++?

1203


Explain function overloading

1060