GeekInterview.com
  I am new, Sign me up!
 
GeekInterview.com  >  Interview Questions  >  Programming  >  C++
Go To First  |  Previous Question  |  Next Question 
 C++  |  Question 21 of 203    Print  
 What do you mean by pure virtual functions?
 
A pure virtual member function is a member function that the base class forces derived classes to provide. Normally these member functions have no implementation. Pure virtual functions are equated to zero.
class Shape { 
public: 
  virtual void draw() = 0; 
}; 
 




  
Total Answers and Comments: 8 Last Update: April 09, 2009   
  
 Sponsored Links

 
 Best Rated Answer

No best answer available. Please pick the good answer available or submit your answer.
July 25, 2006 08:46:29   #1  
Solomon        

RE:  What do you mean by pure virtual ...
And what about entry for pure virtual function in base class virtual table ?? Is this entry empty or equal to NULL?
 
Is this answer useful? Yes | No
October 08, 2006 04:28:30   #2  
Prateek Joshi        

RE:  What do you mean by pure virtual ...

Hi

pure virtual function r the function in which

expresssion 0;

iss present.


 
Is this answer useful? Yes | No
April 09, 2007 09:10:38   #3  
dhanasweet Member Since: March 2007   Contribution: 29    

RE:  What do you mean by pure virtual ...
pure virtual function is a virtual function
in base class it has no definition
derived class has to provide its definition

 
Is this answer useful? Yes | No
October 22, 2007 00:13:11   #4  
krisgroup Member Since: October 2007   Contribution: 8    

RE:  What do you mean by pure virtual ...
hi

adding to above comment

it makes it as a rule to add the implementation in the derived class
or else the derived class inturn becomes an abstract class.

chaitanya

 
Is this answer useful? Yes | No
December 01, 2007 18:23:27   #5  
berezleon Member Since: December 2007   Contribution: 6    

RE:  What do you mean by pure virtual functions?  
Nothing can stop you from implementing pure virtual function; it can be easily called from any of the derived APIs
 
Is this answer useful? Yes | No
February 05, 2008 10:31:49   #6  
Sushant Kadadi Member Since: February 2008   Contribution: 2    

RE:  What do you mean by pure virtual functions?  
internally it tells the compiler to reserve a slot for a function in the VTABLE but not to put an address in the particular slot.
Thus the VTABLE is incomplete.

 
Is this answer useful? Yes | No
April 03, 2008 08:31:20   #7  
chandu_salgar Member Since: April 2008   Contribution: 2    

RE:  What do you mean by pure virtual functions?  
Pure virtual function is a virtual function which has no defination in base class but must be redefined in derieved class or else compile time error will be generated by the compiler.

any class which is having atleast on pure virtual function is termed as an abstract base class (ABC) which cannot be instanciated but we can have a reference or pointer to that class.

for eg :

class myclass {
public:
virtual void display() 0; //pure virtual function with no defination here...
};

class der : public myclass {
public: /*must be redefined in derieved class */
void display() {
cout << blah blah........ << n ;
}
};

 
Is this answer useful? Yes | No
April 09, 2009 07:24:22   #8  
Niranjan.ambati Member Since: April 2009   Contribution: 4    

RE:  What do you mean by pure virtual functions?  

Pure virtual function is the virtual functions which member functions does not have any definitions(implementation) just it equates( ) to 0.
With Pure virtual function the base class becomes "Abstract class". The abstract class does not instantiate/ create objects. But it's pointers can be assigned with Derived class objects.
The pure virtual member functions must be overriden in derived classes.

Hope it helps you in understanding Thanks Niranjan ambati


 
Is this answer useful? Yes | No


 
Go To Top


 Sponsored Links

 
About Us -  Privacy Policy -  Terms and Conditions -  Contact -  Ask Question -  Propose Category -  Site Updates 

Copyright © 2005 - 2009 GeekInterview.com. All Rights Reserved

Page copy protected against web site content infringement by Copyscape