Which one is pure virtual function ?

S

sudhir

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 ?
 
R

Rolf Magnus

sudhir said:
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.
 
D

Daniel T.

"sudhir said:
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.
 
J

Jerry Coffin

@u72g2000cwu.googlegroups.com>,
(e-mail address removed) 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.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,769
Messages
2,569,578
Members
45,052
Latest member
LucyCarper

Latest Threads

Top