473,769 Members | 7,650 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

pure virtual

I don't understand. What's the difference in practice between 2 next lines?
When I *must* use first line and when second?
-------------
virtual int a(int b) = 0;
virtual int a(int b);
-------------

thank you
Jul 19 '05 #1
9 3633
On Sat, 27 Sep 2003 20:13:31 +0300, "<- Chameleon ->"
<ch******@hotma il.NOSPAM.com> wrote:
I don't understand. What's the difference in practice between 2 next lines?
When I *must* use first line and when second?
-------------
virtual int a(int b) = 0;
virtual int a(int b);
-------------

thank you


The first line declares a function a in some class that has no
definition - it is there only to be overridden by derived classes for
the purposes of polymorphism. It also makes the class abstract (unable
to be instantiated). Derived classes must declare and implement this
function or else they too are abstract and un-instatiable. It is
useful in defining an interface.

The second line declares a function a in some class that must have an
implementation for that class. That implementation will be inherited
by derived classes but can still be overridden and perform
polymorphically .

S.
Jul 19 '05 #2
"<- Chameleon ->" <ch******@hotma il.NOSPAM.com> wrote in message
news:bl******** **@nic.grnet.gr ...
I don't understand. What's the difference in practice between 2 next lines? When I *must* use first line and when second?
-------------
virtual int a(int b) = 0;
virtual int a(int b);
-------------

thank you


You may want to look up 'pure virtual'

The first one would be used when defining a pure virtual base class. This
is done in situations where code needs to call the method 'a' for objects of
types which derive from the class but where you need the derived class to
implement the actual method (derived class *must* implement the method). If
we define:

class C
{
Jul 19 '05 #3
Siana wrote:
On Sat, 27 Sep 2003 20:13:31 +0300, "<- Chameleon ->"
<ch******@hotma il.NOSPAM.com> wrote:

I don't understand. What's the difference in practice between 2 next lines?
When I *must* use first line and when second?
-------------
virtual int a(int b) = 0;
virtual int a(int b);
-------------

thank you
The first line declares a function a in some class that has no
definition


That is not true in general. A pure virtual function certainly may have
a definition.
- it is there only to be overridden by derived classes for
the purposes of polymorphism. It also makes the class abstract (unable
to be instantiated). Derived classes must declare and implement this
function or else they too are abstract and un-instatiable. It is
useful in defining an interface.


-Kevin
--
My email address is valid, but changes periodically.
To contact me please use the address from a recent posting.

Jul 19 '05 #4

"Siana" <si************ **************@ yahoo.ca> wrote in message news:vh******** *************** *********@4ax.c om...
The first line declares a function a in some class that has no
definition
Wrong answer. It is the designation of the function as pure virtual.
It does not preclude the function from having a definition. It makes
the class it is defined in abstract. An abstract class is one that can
not be instantiated. It serves only as a base class for others.
- it is there only to be overridden by derived classes for
the purposes of polymorphism.
Not quite, it means that it must be overridden in dervied classes
(as well as all other pure virtual functions) in order to be concrete
(that is, one that can have instances created of it).
The second line declares a function a in some class that must have an
implementation for that class. That implementation will be inherited
by derived classes but can still be overridden and perform
polymorphically .


No it just declares one that is not pure. It means that it doesn't make
the class abstract.

While it is the case that you can omit the implementation of a pure virtual
function, that is secondary to it's meaning.
Jul 19 '05 #5

"<- Chameleon ->" <ch******@hotma il.NOSPAM.com> wrote in message
news:bl******** **@nic.grnet.gr ...
I don't understand. What's the difference in practice between 2 next lines? When I *must* use first line and when second?
-------------
virtual int a(int b) = 0;
virtual int a(int b);
-------------


There is no time when you *must* use the first (pure virtual). It's a
design decision on your part. There are 2 reasons you might use it
a) you want to force any class that inherits from this class to define
function a
b) you want that class to be abstract (no one can make an instance of it -
you can only make instances of subclasses). This is a rather confusing
means of creating an abstract class, but that's the way it is.
Jul 19 '05 #6

"Thomas Wintschel" <th******@telus .net> wrote in message
news:KYkdb.1203 7$o21.6208@edtn ps84...

The first one would be used when defining a pure virtual base class.


You mean an abstract class.
Jul 19 '05 #7

"jeffc" <no****@nowhere .com> wrote in message news:3f******** @news1.prserv.n et...

"Thomas Wintschel" <th******@telus .net> wrote in message
news:KYkdb.1203 7$o21.6208@edtn ps84...

The first one would be used when defining a pure virtual base class.


You mean an abstract class.

Now you're being pedantic :-)
Jul 19 '05 #8

"Ron Natalie" <ro*@sensor.com > wrote in message
news:3f******** *************** @news.newshosti ng.com...

"jeffc" <no****@nowhere .com> wrote in message

news:3f******** @news1.prserv.n et...

"Thomas Wintschel" <th******@telus .net> wrote in message
news:KYkdb.1203 7$o21.6208@edtn ps84...

The first one would be used when defining a pure virtual base class.


You mean an abstract class.

Now you're being pedantic :-)


I knew somone was going to say that :-) The point to my way of thinking is
that "pure virtual base class" is not an OO term, it's not a C++ term, it's
just not any term I've ever heard. I did not of course object to "method",
nor would I even have objected if he used the term "abstract method" for
pure virtual function. I'd be interested in knowing if that's what Thomas
really meant to write and where he heard it. Maybe I should have said "You
mean an abstract class, right?"
Jul 19 '05 #9

"jeffc" <no****@nowhere .com> wrote in message news:3f******** @news1.prserv.n et...

"Ron Natalie" <ro*@sensor.com > wrote in message
news:3f******** *************** @news.newshosti ng.com...

"jeffc" <no****@nowhere .com> wrote in message

news:3f******** @news1.prserv.n et...

"Thomas Wintschel" <th******@telus .net> wrote in message
news:KYkdb.1203 7$o21.6208@edtn ps84...
>
> The first one would be used when defining a pure virtual base class.

You mean an abstract class.

Now you're being pedantic :-)


I knew somone was going to say that :-)


I was just ribbing ya.
Jul 19 '05 #10

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

11
4368
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 it inline. Like this.
37
4179
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 ]
6
3491
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
21
2579
by: sks | last post by:
Hi , could anyone explain me why definition to a pure virtual function is allowed ?
10
4805
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 pure virtual function body
7
24543
by: sam_cit | last post by:
Hi Everyone, I wanted to know as to what is the exact difference between a virtual function and a pure virtual function? Thanks in advance!!!
3
1645
by: keith | last post by:
Dear mentors and gurus, I noticed at the end of section 22.4 of the 'FAQ-Lite' it says "Note that it is possible to provide a definition for a pure virtual function, but this usually confuses novices and is best avoided until later". I've read through all the later stuff, and (although I may have missed it) I can't find anything further on this. Can someone please explain why in all the Halls of Hades you would declare a member...
6
4033
by: Miguel Guedes | last post by:
Hello, I recently read an interview with Bjarne Stroustrup in which he says that pure abstract classes should *not* contain any data. However, I have found that at times situations are when it would be useful to have /some/ data defined in such an abstract class for reasons of forming a common block of data existing in or used by all descendant classes (see example below.) In such a case where a common block of data *always* exists,...
10
2096
by: Rahul | last post by:
Hi, I tried to create a abstract class by having a non-virtual member function as pure, but i got a compilation error saying "only virtual member functions can be pure"... I'm trying to think the reason behind this restriction... i just want to want a base class to be abstract so as to avoid object slicing into the base type from derived type, and in my case base class doesn't need to have a virtual function.
14
2757
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
9423
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 effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
10214
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, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
10048
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 tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
1
9996
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 Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
1
7410
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 presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
6674
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 then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
5304
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 last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
0
5447
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
3963
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system

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.