473,396 Members | 1,766 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,396 software developers and data experts.

Which one is pure virtual function ?

I defined a pure virtual function like

virtual void sum()=0; <--- pure virtual function

but If I defined a virtual function in a base class in case of
multilevel inheritance for the base pointer to point the right function
with same signature in base and derived class like--

virtual void sum() { }

Now is this a pure virtual function or not and class containing this
function is abstract class or not ?

Mar 9 '06 #1
3 2313
sudhir wrote:
I defined a pure virtual function like

virtual void sum()=0; <--- pure virtual function

but If I defined a virtual function in a base class in case of
multilevel inheritance for the base pointer to point the right function
with same signature in base and derived class like--

virtual void sum() { }

Now is this a pure virtual function or not and class containing this
function is abstract class or not ?


Could you please give a full example of what you mean? I couldn't really
follow your description, and sometimes, a few lines of code can say more
than a thousand words.

Mar 9 '06 #2
In article <11**********************@u72g2000cwu.googlegroups .com>,
"sudhir" <su*****************@gmail.com> wrote:
I defined a pure virtual function like

virtual void sum()=0; <--- pure virtual function

but If I defined a virtual function in a base class in case of
multilevel inheritance for the base pointer to point the right function
with same signature in base and derived class like--

virtual void sum() { }

Now is this a pure virtual function or not and class containing this
function is abstract class or not ?


The second function above is implemented (as a no op) so it isn't a pure
virtual function. The class it is in may or may not be abstract
depending on whether there are any unimplemented pure-virtual functions.

--
Magic depends on tradition and belief. It does not welcome observation,
nor does it profit by experiment. On the other hand, science is based
on experience; it is open to correction by observation and experiment.
Mar 9 '06 #3
In article <1141900843.424145.167110
@u72g2000cwu.googlegroups.com>,
su*****************@gmail.com says...
I defined a pure virtual function like

virtual void sum()=0; <--- pure virtual function

but If I defined a virtual function in a base class in case of
multilevel inheritance for the base pointer to point the right function
with same signature in base and derived class like--

virtual void sum() { }

Now is this a pure virtual function or not and class containing this
function is abstract class or not ?


The second is not a pure virtual function.

The difference between the two is simple. In the first
case, you cannot create an instance of this class. To
create an instance, you must derive from this class, and
the pure virtual function must be overridden in a derived
class.

In the second case, you can create an instance of the
class. A derived class may, but is not required to,
override this virtual function. Instances of the derived
class can be created whether the function has been
overridden or not.

--
Later,
Jerry.

The universe is a figment of its own imagination.
Mar 9 '06 #4

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

Similar topics

7
by: A | last post by:
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,
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...
8
by: Zheng Da | last post by:
I don't know where should I ask the question, so send the email to this group. I choose this group, because I want to write the program with c++ :) I want to write a program which support...
3
by: Adriano Coser | last post by:
Hi. I'm declaring a property on a base class that is represented by a pure virtual function. Something like this: public: __declspec( property( get=GetWidth ) ) int Width; virtual int...
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
21
by: sks | last post by:
Hi , could anyone explain me why definition to a pure virtual function is allowed ?
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...
7
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!!!
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
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
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
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
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...

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.