Can anybody explain why can I not get rid of the above message
in the following class definition? [I am using Borland C++ Builder 5.0]
Thank you in advance.
class BasicMidReader : public TMemoryStream
{
//some private date
public:
BasicMidReader( char* FN)
{// some code}
~BasicMidReader () {// some code}
}; 3 3868
"tomek" <ts**@op.pl> wrote: Can anybody explain why can I not get rid of the above message in the following class definition? [I am using Borland C++ Builder 5.0]
.... class BasicMidReader : public TMemoryStream { //some private date public: BasicMidReader( char* FN) {// some code} ~BasicMidReader () {// some code} };
I haven't used Borland C++, but just a guess:
"virtual function 'BasicMidReader ::~BasicMidRead er()' conflicts with base
class" sounds like TMemoryStream could have a virtual destructor, and you
haven't declared ~BasicMidReader () as virtual. If so, I would expect this to
be a warning rather than an error, since inherited virtual functions are
also virtual - even if they don't say so (but they should !)
(BTW: in general, all destructors should be virtual unless you are sure the
class will never be used as a base class - this even applies if the
destructor is empty (ie. there is nothing to explicitly delete)).
David F
"David Fisher" <no****@nospam. nospam.nospam> wrote... "tomek" <ts**@op.pl> wrote:
Can anybody explain why can I not get rid of the above message in the following class definition? [I am using Borland C++ Builder 5.0] ... class BasicMidReader : public TMemoryStream { //some private date public: BasicMidReader( char* FN) {// some code} ~BasicMidReader () {// some code} };
I haven't used Borland C++, but just a guess:
"virtual function 'BasicMidReader ::~BasicMidRead er()' conflicts with base class" sounds like TMemoryStream could have a virtual destructor, and you haven't declared ~BasicMidReader () as virtual. If so, I would expect this
to be a warning rather than an error, since inherited virtual functions are also virtual - even if they don't say so (but they should !)
Why should they? If the language says that 'if any base class has
a virtual destructor, the class' destructor is virtual even if not
declared such', why declare it virtual? It's virtual already.
(BTW: in general, all destructors should be virtual unless you are sure
the class will never be used as a base class - this even applies if the destructor is empty (ie. there is nothing to explicitly delete)).
That is nonsense. Even if you use some class as a base class for
something else, its destructor doesn't have to be virtual if you
will never delete a dynamically allocated object polymorphically .
Declaring functions virtual when there is no need, only leads to
performance degradation and wasted space.
Victor
"Victor Bazarov" <v.********@com Acast.net> wrote: inherited virtual functions are also virtual - even if they don't say so (but they should !)
Why should they? If the language says that 'if any base class has a virtual destructor, the class' destructor is virtual even if not declared such', why declare it virtual? It's virtual already.
Just to make it clearer to the reader. (BTW: in general, all destructors should be virtual unless you are sure
the class will never be used as a base class - this even applies if the destructor is empty (ie. there is nothing to explicitly delete)).
That is nonsense. Even if you use some class as a base class for something else, its destructor doesn't have to be virtual if you will never delete a dynamically allocated object polymorphically .
Declaring functions virtual when there is no need, only leads to performance degradation and wasted space.
Of course; I should have said, "unless you are sure the class will never be
used as a polymorphic base class." But assuming that the writer does not
have complete control over the future use of the class (which is most of the
time in a software company), you never know how the class is going to be
modified over time. It is also easy to forget to make a destructor virtual,
and hard to track this down if there is a problem (it happened to me !)
David F This thread has been closed and replies have been disabled. Please start a new discussion. Similar topics |
by: Lefevre |
last post by:
Hello
I recently had troubles with a class inheritance hierarchy.
I solved it, but it didn't satisfied me.
I found the solution using this forum :)
Actualy i found the following message (with no responces associated) :
|
by: Michael Winter |
last post by:
Until about 5 minutes ago, I was happy with my knowledge of virtual
functions - then I read "Mixing interface and functional inheritance"
posted by Kevin L. earlier today. All of a sudden, I found out that
you can inherit using the virtual keyword:
class A
{
}
class B : public *virtual* A
|
by: dumboo |
last post by:
hi there
i m having a base class
class base
{
...
};
and two derived class, which have inherited 'base' but the inheritance is
not virtual
|
by: Chunhui Han |
last post by:
Hi,
I was recently reading about virtual base classes in C++. The book I was
reading says that it is illegal to have non-virtual destructor for the
virtual base class. It seems to me that virtual destructors are essential
when the class has virtual functions, since this class is supposed to be
used as a base class for polymorphism. But what is the real reason for a
virtual destructor in a virtual base class?
Thanks,
|
by: mshetty |
last post by:
Hi,
I get an error "Warning: b::a_method hides the virtual function
a::a_method()."
on compiling the following code..
#include <iostream.h>
class a
{
| |
by: rbfish |
last post by:
Hi,
How can I call a virtual base function with variable parameters? like,
class base
{
public:
int printf(const char *fmt, ...)
{
// do anything here.
|
by: nw |
last post by:
Hi,
I have three classes, a template pure virtual base class, a template
derived class and a third which I would like to use to store copies of
the derived class. The code looks like this:
#include <iostream>
#include <vector>
using namespace std;
|
by: reppisch |
last post by:
Hi Ng,
besides that this style may be asking for trouble i'm faced with a
unexpected gcc behaviour. Tested with gcc 3.3.3.
On M$ .Net this compiles just fine.
I'm trying to make a non-const reference to a temporary object. The
object is derived from a pure virtual base, so the compiler can't create
a copy of base-type.
|
by: =?Utf-8?B?Zmplcm9uaW1v?= |
last post by:
Hi all,
As I mentioned in a previous thread (see 'Dbghelp, symbols and templates' in
microsoft.public.windbg), we created a powerful symbol engine using dbghelp
to dump the contents of the stack symbols when an exception occurs.
The engine is able to dereference and process UDT symbols up to their
highest base class. It also supports multiple inheritance. However, we are
having trouble with virtual inheritance. Documentation is very...
|
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 effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it.
First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
|
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, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed.
This is as boiled down as I can make it.
Here is my compilation command:
g++-12 -std=c++20 -Wnarrowing bit_field.cpp
Here is the code in...
| |
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 protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
|
by: agi2029 |
last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own....
Now, this would greatly impact the work of software developers. The idea...
|
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 presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules.
He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms.
Adolph will...
|
by: conductexam |
last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one.
At the time of converting from word file to html my equations which are in the word document file was convert into image.
Globals.ThisAddIn.Application.ActiveDocument.Select();...
|
by: TSSRALBI |
last post by:
Hello
I'm a network technician in training and I need your help.
I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs.
The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols.
I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
|
by: adsilva |
last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
| |
by: bsmnconsultancy |
last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...
| |