Re: Converting a Glib::ValueBase to a derived type
- From: Hubert Figuiere <hub figuiere net>
- To: José Alburquerque <jaalburquerque cox net>
- Cc: gtkmm-list <gtkmm-list gnome org>
- Subject: Re: Converting a Glib::ValueBase to a derived type
- Date: Wed, 30 Jan 2008 00:09:28 -0500
On Tue, 2008-01-29 at 23:48 -0500, José Alburquerque wrote:
> I'm wondering, would anyone know how to convert a Glib::ValueBase to one
> of its derived types (such as Glib::Value<int>) assuming the derived
> type has been returned from a function as the base class
> Glib::ValueBase? I'm writing some code that would conveniently return a
> derived Glib::ValueBase as a Glib::ValueBase and really don't know how
> to convert it back to the derived type once it's been returned. Thanks.
dynamic_cast<Glib::Value<int> *>(value);
(if value is actually a pointer like Glib::ValueBase*)
will return NULL if it can't convert.
If value is not a pointer type, do this:
dynamic_cast<Glib::Value<int> &>(value);
It will return a reference to value, or throw an exception if it can't
cast.
This is standard C++
Hub
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]