468,780 Members | 2,286 Online
Bytes | Developer Community
New Post

Home Posts Topics Members FAQ

Post your question to a community of 468,780 developers. It's quick & easy.

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 2121
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 discussion thread is closed

Replies have been disabled for this discussion.

Similar topics

7 posts views Thread by A | last post: by
11 posts views Thread by santosh | last post: by
8 posts views Thread by Zheng Da | last post: by
3 posts views Thread by Adriano Coser | last post: by
6 posts views Thread by pakis | last post: by
21 posts views Thread by sks | last post: by
7 posts views Thread by sam_cit | last post: by
1 post views Thread by CARIGAR | last post: by
2 posts views Thread by Marin | last post: by
By using this site, you agree to our Privacy Policy and Terms of Use.