Sunday, April 26, 2009

virtual n pure virtual function..

Question:
Tell me what is the use of pure virtual function as it contains no definition or declaration.... n also the diffrence in them

Answers:

resence of a pure virtual function in a class makes the class abstract.
If a class has, say, N number of pure virtual functions, then the class derived from this (abstract) class needs to define its version of all the pure virtual functions. If it misses out even one function, then that class would also become a abstract class.
 
A class is made abstract if :
 
1. It makes no sense in creating an instance of that type.
2. It is required that all classes that inherit that class must give their respective definition(s) of some function(s).
 
__________
 
For more info, read a GOOD book.
I suggest C++ Primer and Thinking in C++( By Bruce Eckel).


Answer2:

Pure virtual functions are used to make a class abstract.

Then what is the use of abstract class??
To make interface for a module.

In C,we give a header file contains list of functions(APIs).
Other internal functions we can make static for internal function call.

Similarly in C++,its object oriented programming,we make interfaces while 
doing the class diagram in design.
We make some classes(functions in C) as interface,which is visible to outside user.
Using those class pointer we access actual objects like virtual functions.

Any More Answers?


No comments:

Post a Comment

Note: Only a member of this blog may post a comment.