Should we use pure virtual function in all case for polymorphism?

J

Jim Langston

is that true for the statement?

thanks.

No. If a method has something that will work for most, or all, cases it
doesn't need to be pure virtual, just virtual.
 
H

howachen

Jim Langston 寫é“:
No. If a method has something that will work for most, or all, cases it
doesn't need to be pure virtual, just virtual.

in this case...why put a virtual then? since all class will have the
same implementation...just inheri it
 
D

Duane Hebert

in this case...why put a virtual then? since all class will have the
same implementation...just inheri it

Notice that he said "for most or all", not "for all."
Are you concerned about overhead of the vtable?
 
J

Jim Langston

Jim Langston ??:
in this case...why put a virtual then? since all class will have the
same implementation...just inheri it

Unless you want the method to be unmutable, it is generally a good idea to
make it virtual anyway, just in case you find later that you want to change
something in a derived class. It is better, IMO, to initially make it
virtual than to have to modify the base class later because you realize that
with some derived class you need to override a base method you thought you
wouldn't have to when you designed the base class.
 

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

No members online now.

Forum statistics

Threads
474,432
Messages
2,571,682
Members
48,796
Latest member
Greg L.

Latest Threads

Top