"interface"

S

seesaw

When define an interface of all pure virtual functions, will the destructor
of it will automatically virtual, or it has to be declared as virtual?
Should it be declared as "virtual" when defining the interface?
 
P

Phlip

seesaw said:
When define an interface of all pure virtual functions, will the destructor
of it will automatically virtual, or it has to be declared as virtual?
Should it be declared as "virtual" when defining the interface?

In C++, you don't pay for what you don't use.

Suppose, someday many winters from now, you wrote a program, and then
profiled it, and discovered the only way to make it faster was to take out a
single virtual destructor.

If the C++ committees had decreed that undeclared destructors of purely
abstract base classes were magically virtual, you would be screwed.

So, until that day, get in the habit of writing...

virtual ~myClass() = 0;

....to make destructors pure virtual, too.

(If the abstract class weren't pure - if it had a member that needs
destruction, the = 0 won't prevent this.)
 
J

John Carson

seesaw said:
When define an interface of all pure virtual functions, will the
destructor of it will automatically virtual, or it has to be declared
as virtual? Should it be declared as "virtual" when defining the
interface?

It has to be declared virtual.
 

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,577
Members
45,052
Latest member
LucyCarper

Latest Threads

Top