Re: How do I find out an object's type using the GTK+ (1.2) type syst em?
- From: Havoc Pennington <hp redhat com>
- To: "Bowman, Michael W. (MBOWMAN)" <MBOWMAN arinc com>
- Cc: "'gtk-list gnome org'" <gtk-list gnome org>
- Subject: Re: How do I find out an object's type using the GTK+ (1.2) type syst em?
- Date: 22 Feb 2002 23:40:41 -0500
"Bowman, Michael W. \(MBOWMAN\)" <MBOWMAN arinc com> writes:
> I have a situation like the following:
>
> void
> setParms(GtkOpenmapProj* proj, ...) {
> ...
> class->normalize_latitude(proj, ...);
> }
>
> GtkOpenmapProj is a base class that has multiple sub-types. Each of the
> subtypes may
> override the normalize_latitude method of the GtkOpenmapProj class. However,
> I don't
> know which of the subtypes is passed into my function, just that its some
> sub-type of
> GtkOpenmapProj. How do I find which type identifier to feed to
> gtk_type_class() so
> that I can obtain the class struct for the proper sub-type (and use the
> proper
> normalize_latitude function)? How does GTK+ handle polymorphism?
Just look at any example in GTK itself. You should not need the
subtype's class, just GtkOpenmapProjClass, which contains the
normalize_latitude function.
The whole point of virtual functions is you don't have to know the
type of the object, isn't it?
Usually people write a wrapper function:
void
gtk_openmap_proj_normalize_latitude (GtkOpenmapProj *proj)
{
GTK_OPENMAP_PROJ_GET_CLASS (proj)->normalize_latitude (proj);
}
Havoc
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]