472,981 Members | 1,451 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 472,981 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 2290
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: lllomh | last post by:
Define the method first this.state = { buttonBackgroundColor: 'green', isBlinking: false, // A new status is added to identify whether the button is blinking or not } autoStart=()=>{
2
by: DJRhino | last post by:
Was curious if anyone else was having this same issue or not.... I was just Up/Down graded to windows 11 and now my access combo boxes are not acting right. With win 10 I could start typing...
2
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 4 Oct 2023 starting at 18:00 UK time (6PM UTC+1) and finishing at about 19:15 (7.15PM) The start time is equivalent to 19:00 (7PM) in Central...
0
by: Aliciasmith | last post by:
In an age dominated by smartphones, having a mobile app for your business is no longer an option; it's a necessity. Whether you're a startup or an established enterprise, finding the right mobile app...
4
NeoPa
by: NeoPa | last post by:
Hello everyone. I find myself stuck trying to find the VBA way to get Access to create a PDF of the currently-selected (and open) object (Form or Report). I know it can be done by selecting :...
3
NeoPa
by: NeoPa | last post by:
Introduction For this article I'll be using a very simple database which has Form (clsForm) & Report (clsReport) classes that simply handle making the calling Form invisible until the Form, or all...
1
by: Teri B | last post by:
Hi, I have created a sub-form Roles. In my course form the user selects the roles assigned to the course. 0ne-to-many. One course many roles. Then I created a report based on the Course form and...
3
by: nia12 | last post by:
Hi there, I am very new to Access so apologies if any of this is obvious/not clear. I am creating a data collection tool for health care employees to complete. It consists of a number of...
4
by: GKJR | last post by:
Does anyone have a recommendation to build a standalone application to replace an Access database? I have my bookkeeping software I developed in Access that I would like to make available to other...

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.