By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
446,418 Members | 1,094 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 446,418 IT Pros & Developers. It's quick & easy.

is this undefined?

P: n/a
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?

--
ES Kim

Jul 19 '05 #1
Share this Question
Share on Google+
2 Replies


P: n/a
"ES Kim" <es***@svd.co.kr> wrote in message
news:bg**********@news1.kornet.net...
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.
--
jb

(replace y with x if you want to reply by e-mail)
Jul 19 '05 #2

P: n/a


ES Kim wrote:

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.

--
Karl Heinz Buchegger
kb******@gascad.at
Jul 19 '05 #3

This discussion thread is closed

Replies have been disabled for this discussion.