linux-c-programming.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: "Steve Graegert" <graegerts@gmail.com>
To: linux-c-programming@vger.kernel.org
Subject: Re: Virtual functions and destructors
Date: Sun, 19 Mar 2006 17:38:52 +0000	[thread overview]
Message-ID: <6a00c8d50603190938v5852f31bhd1a6dfa7262ef83@mail.gmail.com> (raw)
In-Reply-To: <200603192050.22014.samjnaa@gmail.com>

On 3/19/06, Shriramana Sharma <samjnaa@gmail.com> wrote:
> I did not get what is intended to be conveyed by:
>
> http://charm.cs.uiuc.edu/users/olawlor/ref/examples/cpp/virtual.cpp
> http://charm.cs.uiuc.edu/users/olawlor/ref/examples/cpp/virtual_destructor.cpp

1. In C++ the virtual keyword identifies to the compiler that a class
function may be overridden in a derived class.  That is, the derived
class may supply a function of the same name and argument list, but
with different functionality defined in the function body.  In the
example you linked to the child class has overriden the virtual
function hello and allows itself to be overridden by declaring its
function virtual as well.  A pointer to a derived class object may be
assigned to a base class pointer, and a virtual function called
through the pointer. If the function is virtual and occurs both in the
base class and in derived classes, then the right function will be
picked up based on what the base class pointer "really" points at.

2. Virtual destructors are needed to allow for the destructors for the
actual object types derived from the base class to be called.  Non
virtual destructors in base classes can result in memory leaks.

	\Steve

  reply	other threads:[~2006-03-19 17:38 UTC|newest]

Thread overview: 6+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2006-03-19 15:20 Virtual functions and destructors Shriramana Sharma
2006-03-19 17:38 ` Steve Graegert [this message]
2006-03-22 22:27   ` Benjamin Sobotta
2006-03-23  2:02     ` Shriramana Sharma
2006-03-23 22:00       ` Benjamin Sobotta
2006-03-24  1:07         ` Glynn Clements

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=6a00c8d50603190938v5852f31bhd1a6dfa7262ef83@mail.gmail.com \
    --to=graegerts@gmail.com \
    --cc=linux-c-programming@vger.kernel.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).