By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
446,148 Members | 1,373 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 446,148 IT Pros & Developers. It's quick & easy.

C++: Virtual fnc Vs Pure fnc?

P: n/a
A
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
Jul 19 '05 #1
Share this Question
Share on Google+
7 Replies


P: n/a
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.
Jul 19 '05 #2

P: n/a
> 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
Jul 19 '05 #3

P: n/a

"EventHelix.com" <ev********@hotmail.com> wrote in message news:56**************************@posting.google.c 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.
Jul 19 '05 #4

P: n/a
osmium <r1********@comcast.net> wrote in message
news:bp*************@ID-179017.news.uni-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.
Jul 19 '05 #5

P: n/a
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

Jul 22 '05 #6

P: n/a

"Mike Smith" <mi*******************@acm.DOT.org> wrote in message news:vr************@news.supernews.com...
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.

Jul 22 '05 #7

P: n/a

"Ron Natalie" <ro*@sensor.com> wrote in message
news:3f***********************@news.newshosting.co 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.
Jul 22 '05 #8

This discussion thread is closed

Replies have been disabled for this discussion.