473,463 Members | 1,515 Online
Bytes | Software Development & Data Engineering Community
Create Post

Home Posts Topics Members FAQ

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 11176
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>
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
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...
1
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
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
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
0
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and...
0
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The...

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.