Re: Creating custom GTK+ widget using C++ -- Ctor/Dtor not called
- From: David Nečas <yeti physics muni cz>
- To: Agnel Kurian <agnel kurian gmail com>
- Cc: gtk-list gnome org
- Subject: Re: Creating custom GTK+ widget using C++ -- Ctor/Dtor not called
- Date: Thu, 16 Feb 2012 00:14:19 +0100
On Thu, Feb 16, 2012 at 04:05:19AM +0530, Agnel Kurian wrote:
> I have implemented a custom GTK+ widget which relies on a C++ object
> internally. i.e. the widget structure contains an instance of a C++ class.
> My concern was that the constructor and destructor of the contained object
> were not being called. I had assumed that merely compiling as C++ would
> make it work... but now I realize it need not be so when allocated via
> g_object_new.
It will not work if you embed the C++ class within the GObject struct
because the GObject struct is simply allocated as a block of memory from
the heap (using GSlice or whatever but anyway no C++ new operator is
involved).
You can create C++ objects in the instance-init method of the GObject
and then, for example, put pointers to them to the GObject struct and
destroy them in the the GObject finalize method.
If you just want this and not any of the fancy stuff cxx-gtk-utils does
then it is quite trivial and you do not need any extra library.
Yeti
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]