473,399 Members | 4,254 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,399 software developers and data experts.

C++: Virtual fnc Vs Pure fnc?

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
7 11172
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
> 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

"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
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
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

"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

"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 thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

39
by: Ele | last post by:
Is it correct to say that Whenever a class has a virtual member function, define its destructor as "virtual"? Can a destructor as "pure virtual"? When is it needed to do so? For an interface,...
2
by: sam++ | last post by:
Hi, I created a pure virtual class P and its derived sub-class D. In class P, declared a pure virtural function pure(); in sub-class D define its implementation. eg. class P {
11
by: santosh | last post by:
Hello, I was going through the Marshal Cline's C++ FAQ-Lite. I have a doubt regarding section 33.10. Here he is declaring a pure virtual destructor in the base class. And again defining...
37
by: WittyGuy | last post by:
Hi, I wonder the necessity of constructor and destructor in a Abstract Class? Is it really needed? ? Wg http://www.gotw.ca/resources/clcm.htm for info about ]
12
by: placid | last post by:
Hi if a have the following classes class A { public: A(); virtual ~A(); virtual string someFunction() const = 0;
6
by: pakis | last post by:
I am having a problem of pure virtual function call in my project. Can anyone explaine me the causes of pure virtual function calls other than calling a virtual function in base class? Thanks
2
by: Heinz Ketchup | last post by:
Hello, I'm looking to bounce ideas off of anyone, since mainly the idea of using Multiple Virtual Inheritance seems rather nutty. I chalk it up to my lack of C++ Experience. Here is my...
10
by: John Goche | last post by:
Hello, page 202 of Symbian OS Explained by Jo Stichbury states "All virtual functions, public, protected or private, should be exported" then page 203 states "In the rare cases where a...
17
by: Jess | last post by:
Hello, If I have a class that has virtual but non-pure declarations, like class A{ virtual void f(); }; Then is A still an abstract class? Do I have to have "virtual void f() = 0;"...
14
by: Jack | last post by:
Hi, I meet a question with it , I did not get clear the different betteen them, for example: #include <iostream>
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.