473,407 Members | 2,359 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,407 software developers and data experts.

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

is that true for the statement?

thanks.

Oct 7 '06 #1
5 1491
Howachen posted:
is that true for the statement?

Ask the chap that sits beside you.

--

Frederick Gotham
Oct 7 '06 #2
<ho******@gmail.comwrote in message
news:11**********************@m73g2000cwd.googlegr oups.com...
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.
Oct 7 '06 #3

Jim Langston 寫道:
<ho******@gmail.comwrote in message
news:11**********************@m73g2000cwd.googlegr oups.com...
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.
in this case...why put a virtual then? since all class will have the
same implementation...just inheri it

Oct 7 '06 #4

<ho******@gmail.comwrote in message
news:11**********************@h48g2000cwc.googlegr oups.com...
>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
Notice that he said "for most or all", not "for all."
Are you concerned about overhead of the vtable?
Oct 7 '06 #5
<ho******@gmail.comwrote in message
news:11**********************@h48g2000cwc.googlegr oups.com...

Jim Langston ??:
><ho******@gmail.comwrote in message
news:11**********************@m73g2000cwd.googleg roups.com...
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.
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.
Oct 8 '06 #6

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

Similar topics

9
by: | last post by:
I don't understand. What's the difference in practice between 2 next lines? When I *must* use first line and when second? ------------- virtual int a(int b) = 0; virtual int a(int b);...
37
by: WittyGuy | last post by:
Hi, I wonder the necessity of constructor and destructor in a Abstract Class? Is it really needed? ? Wg http://www.gotw.ca/resources/clcm.htm for info about ]
3
by: sudhir | last post by:
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...
21
by: sks | last post by:
Hi , could anyone explain me why definition to a pure virtual function is allowed ?
7
by: eric | last post by:
hello i'm confused by an example in the book "Effective C++ Third Edition" and would be grateful for some help. here's the code: class Person { public: Person(); virtual ~Person(); // see...
3
by: gabriel.becedillas | last post by:
Hi, I'm having problems wrapping a hierarchy of classes, actually having problems wrapping the base class. I don't need to use the WrapClass mechanism since I don't want to override classes in...
7
by: Markus Svilans | last post by:
Hello, My question involves virtual functions and inheritance. Suppose we have a class structure, that consists of "data" classes, and "processor" classes. The data classes are derived from...
10
by: Rahul | last post by:
Hi, I tried to create a abstract class by having a non-virtual member function as pure, but i got a compilation error saying "only virtual member functions can be pure"... I'm trying to think...
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: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
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:
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
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
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...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...

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.