Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > C++ > C++: Virtual fnc Vs Pure fnc?

Reply
Thread Tools

C++: Virtual fnc Vs Pure fnc?

 
 
A
Guest
Posts: n/a
 
      11-15-2003
Hi,

1) Whats the difference from a virtual function and a pure virtual function?

2) When would you use one over the over?

3) What's the significance of the word virtual?


Regards,
A


 
Reply With Quote
 
 
 
 
osmium
Guest
Posts: n/a
 
      11-15-2003
A wrote:

> 1) Whats the difference from a virtual function and a pure virtual

function?
>
> 2) When would you use one over the over?
>
> 3) What's the significance of the word virtual?


That's a question I would normally try to answer, but it sounds just too
much like a take-home test. Try google. If you answer 1 and 2 the answer
to 3 should almost be a side effect.


 
Reply With Quote
 
 
 
 
EventHelix.com
Guest
Posts: n/a
 
      11-15-2003
> 1) Whats the difference from a virtual function and a pure virtual function?

Virtual functions that must be overriden by the inheriting class are pure
virtual function.

> 2) When would you use one over the over?


Use virtual functions when the base class can provide a reasonable
default handling for the method. Use pure virtual when the base class
just defines the interface for the function and no default handling
is applicable.

> 3) What's the significance of the word virtual?


What's in a name? Virtual is a misleading keyword for overridable

Sandeep
--
http://www.EventHelix.com/EventStudio
EventStudio 2.0 - Generate Sequence Diagrams and Use Case Diagrams in PDF
 
Reply With Quote
 
Ron Natalie
Guest
Posts: n/a
 
      11-15-2003

"EventHelix.com" <(E-Mail Removed)> wrote in message news:(E-Mail Removed) om...
> > 1) Whats the difference from a virtual function and a pure virtual function?

>
> Virtual functions that must be overriden by the inheriting class are pure
> virtual function.


....or the derived class remains abstract.
>
> > 2) When would you use one over the over?

>
> Use virtual functions when the base class can provide a reasonable
> default handling for the method. Use pure virtual when the base class
> just defines the interface for the function and no default handling
> is applicable.


Or when you wish to force the derived class to at least think about whether
the base class default is appropriate. There's no requirement that the base
class not implement a pure virtual.

> > 3) What's the significance of the word virtual?

> What's in a name? Virtual is a misleading keyword for overridable


Virtual...by definition: in appearance but not in fact. While it appears
you are calling the base class function, you are in fact calling the one from
the derived class.


 
Reply With Quote
 
Deming He
Guest
Posts: n/a
 
      11-16-2003
osmium <(E-Mail Removed)> wrote in message
news:bp55vu$1kfnr8$(E-Mail Removed)-berlin.de...
> A wrote:
>
> > 1) Whats the difference from a virtual function and a pure virtual

> function?
> >

Also, for a virtual function you need an implementation as a place holder,
but for pure virtual, you don't.


 
Reply With Quote
 
Mike Smith
Guest
Posts: n/a
 
      11-18-2003
EventHelix.com wrote:
>
> What's in a name? Virtual is a misleading keyword for overridable


It's more than that. Non-virtual functions can be overridden, too. The
difference is *polymorphism*.

--
Mike Smith

 
Reply With Quote
 
Ron Natalie
Guest
Posts: n/a
 
      11-18-2003

"Mike Smith" <(E-Mail Removed)> wrote in message news:(E-Mail Removed)...
> EventHelix.com wrote:
> >
> > What's in a name? Virtual is a misleading keyword for overridable

>
> It's more than that. Non-virtual functions can be overridden, too. The
> difference is *polymorphism*.


Non-virtual functions are not overriden. The definition of override in C++
is based on virtual functions (10.3/2):

If a virtual member function vf is declared in a class Base and in a class Derived, derived directly or
indirectly from Base, a member function vf with the same name and same parameter list as Base::vf is
declared, then Derived::vf is also virtual (whether or not it is so declared) and it overrides Base::vf.



 
Reply With Quote
 
jeffc
Guest
Posts: n/a
 
      11-18-2003

"Ron Natalie" <(E-Mail Removed)> wrote in message
news:3fb660be$0$75702$(E-Mail Removed) m...
> There's no requirement that the base
> class not implement a pure virtual.


For some reason, this is not intuitive for the vast majority of programmers.


 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Need clarification for virtual method and pure virtual function a C++ 7 06-28-2007 12:38 PM
virtual vs pure virtual member function sam_cit@yahoo.co.in C++ 7 05-02-2007 10:00 AM
private virtual functions and pure virtual functions with bodies John Goche C++ 10 12-08-2006 04:00 PM
Pure functions still pure after definition Todd Aspeotis C++ 3 05-30-2005 03:53 AM
virtual function and pure virtual function in the implementation of COM IK C++ 2 07-23-2004 02:55 PM



Advertisments