is this undefined?

E

ES Kim

The destructor of a base class should be virtual in order to
ensure that the correct sequence of destructors is called.
But how about if the derived class has no additional member?
For example,

class Base
{
public:
~Base() { }
/* declaration of other members */
};

class Derived : public Base { };

Base* b = new Derived;
delete b;

Is this undefined?
 
J

Jakob Bieling

ES Kim said:
The destructor of a base class should be virtual in order to
ensure that the correct sequence of destructors is called.
But how about if the derived class has no additional member?
For example,

class Base
{
public:
~Base() { }
/* declaration of other members */
};

class Derived : public Base { };

Base* b = new Derived;
delete b;

Is this undefined?


Yes. The fact that the derived class does not have any members does not
change this.
 
K

Karl Heinz Buchegger

ES said:
The destructor of a base class should be virtual in order to
ensure that the correct sequence of destructors is called.
But how about if the derived class has no additional member?
For example,

class Base
{
public:
~Base() { }
/* declaration of other members */
};

class Derived : public Base { };

Base* b = new Derived;
delete b;

Is this undefined?

yes.
Even if *you* added no members to your class, the compiler
might add something to it.
 

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
474,138
Messages
2,570,801
Members
47,348
Latest member
nethues

Latest Threads

Top