Re: Pointer casting related question



On Mon, 7 Aug 2017 13:58:07 +0100
Daniel Boles <dboles src gmail com> wrote:
use Glib::RefPtr<destination_type>::cast_dynamic(source_refptr)

or cast_static if you can guarantee that the cast is valid, does not
require adjustment for multiple/virtual inheritance, and don't want
the (probably insignificant) overhead of a checked cast.

see:
https://developer.gnome.org/glibmm/stable/classGlib_1_1RefPtr.html#afba688c406f0c3d1239c6b7c3716c1de
https://mail.gnome.org/archives/gtkmm-list/2010-August/msg00051.html

A static cast will carry out pointer adjustment when traversing an
inheritance graph to account for multiple inheritance or a vtable.  It
is reinterpret cast which will not.

A static cast does not allow a direct cast between two siblings in
a multiple inheritance graph (you will get a compiler error unless you
do it in two stages via a common parent), and as you say it does not
check for validity.


[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]