Re: vfunc question
- From: "Murray Cumming" <murrayc murrayc com>
- To: "Johannes Schmid" <johannes schmid gmx de>
- Cc: gtkmm-list gnome org
- Subject: Re: vfunc question
- Date: Thu, 21 Sep 2006 14:59:07 +0200 (CEST)
> -----BEGIN PGP SIGNED MESSAGE-----
> Hash: SHA1
>
> Hi!
>
> After being able to load my C++ plugin in Anjuta I have a problem
> calling it's activate function.
>
> bool activate() is a virtual function wrapped using _WRAP_VFUNC().
> However, the C code calls klass->activate which ends up calling
> Anjuta::Plugin::activate_vfunc_callback which then calls
> Plugin::activate_vfunc().
>
> Anyway, activate_vfunc() contains
>
> bool Anjuta::Plugin::activate_vfunc()
> {
> BaseClassType *const base = static_cast<BaseClassType*>(
> g_type_class_peek_parent(G_OBJECT_GET_CLASS(gobject_)) // Get the
> parent class of the object class (The original underlying C class).
> );
>
> if(base && base->activate)
> return (*base->activate)(gobj());
>
> typedef bool RType;
> return RType();
> }
>
> But this code will never ever calls the overridden activate() function
> of my derived SamplePlugin class.
An activate() function in your derived class has nothing to do with this.
To override the "activate" vfunc (technically a function pointer in the C
struct) in a gtkmm class, you must override activate_vfunc().
The _vfunc() suffix was added in gtkmm to avoid clashes with similarly
named methods. For instance, a GTK+ widget can have a vfunc called
something and a method called something. It's not a clash in C:
struct Example
{
...
}
struct Example_Class
{
...
void (*something)(Example*, int)
}
example_something(Example* example, double a, double b)
> Is this intended? I feel that I
> completely misunderstand some things with virtual functions because what
> I want is that klass->activate() ends up calling SamplePlugin::activate().
So your knowledge of the C API is the problem. Just override the C++
virtual method that exists.
Murray Cumming
murrayc murrayc com
www.murrayc.com
www.openismus.com
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]