Virtual function 'BasicMidReader::~BasicMidReader()' conflicts with base class 'base 'TMemoryStream'



 DEVELOP > c-Plus-Plus > Virtual function 'BasicMidReader::~BasicMidReader()' conflicts with base class 'base 'TMemoryStream'

LINK TO THIS PAGE  


rating :  0   |  0


  Page 1 of 1

1

 
Topic: DEVELOP > c-Plus-Plus
User: "tomek"
Date: 26 Nov 2003 07:40:31 PM
Object: Virtual function 'BasicMidReader::~BasicMidReader()' conflicts with base class 'base 'TMemoryStream'
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}
};
.

User: "David Fisher"

Title: Re: Virtual function 'BasicMidReader::~BasicMidReader()' conflicts with base class 'base 'TMemoryStream' 28 Nov 2003 08:34:59 PM
"tomek" <tszp@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::~BasicMidReader()' 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
.
User: "Victor Bazarov"

Title: Re: Virtual function 'BasicMidReader::~BasicMidReader()' conflicts with base class 'base 'TMemoryStream' 29 Nov 2003 12:03:41 PM
"David Fisher" <nospam@nospam.nospam.nospam> wrote...

"tomek" <tszp@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::~BasicMidReader()' 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
.
User: "David Fisher"

Title: Re: Virtual function 'BasicMidReader::~BasicMidReader()' conflicts with base class 'base 'TMemoryStream' 29 Nov 2003 06:18:26 PM
"Victor Bazarov" <v.Abazarov@comAcast.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
.




  Page 1 of 1

1

 


Related Articles
Virtual function 'BasicMidReader::~BasicMidReader()' conflicts with base class 'base 'TMemoryStream'
Cast from void* to base class virtual function problem
How to determine if virtual function in base class is overriden?
How can i force my derivers to call a base function
Can a class call its indirect base's member function?
Problem with virtual member function pointer (how to invoke the base?!)
Accessing base class function
Why polymorph fails when virtual function is decleared private in base class and public in derived class?
Can pure virtual function be called in base class constructor?
Accessing Base class function using a pointer to a derived class
pointer to virtual function of a base class
Calling virtual override from base function fails
calling virtual function results in calling function of base class ...
exception virtual function through base class
Calling protected base class function on other (same typed) object
 

NEWER

pg.1232     pg.940     pg.716     pg.544     pg.412     pg.311     pg.234     pg.175     pg.130     pg.96     pg.70     pg.50     pg.35     pg.24     pg.16     pg.10     pg.6     pg.3     pg.1

OLDER