Re: Using C++ Data Types in Custom Gtk+ Classes



On Saturday 22 April 2006 01:57, Andrew Krause wrote:
> As anyone can see from the title, I am trying to use a C++ data
> type such as a string or vector as a member in a custom Gtk+
> class. Here is a little example of what I mean:
>
> struct Custom
> {
>  GtkNotebook parent;
>  vector<string> list;
> };
>
> struct CustomClass
> {
>  GtkNotebookClass parent_class;
> };
>
> When I do this, I keep getting segmentation faults from the debugger.
> The output of gdb keeps telling me I cannot do anything with those
> variables. For example, if I include a string, when I try to set it
> equal to
> some text, it tells me it crashed in the "assign()" function.
>
> I have had problems integrating C++ and Gtk+ before, but I do not want
> to use Gtkmm. I used it before and it added too much extra baggage on
> the executable.
>
> Thanks for any help you can offer! - Andrew Krause

Your example doesn't make sense since as it does not do anything.

However, you should store GTK+ objects by pointer, and you should create them 
using the appropriate GTK+ function.  The structures of which GTK+ widgets 
are formed are not default constructible, copy constructible or copy 
assignable.

If you consider the effect of this statement:

  CustomClass custom_class;

then all should become clear.

There is nothing amiss with your use of vector<string> in your class 
definition (other than the absence of a namespace identifier and the odd 
choice of name of the object you have declared), so from the error you report 
the code you have written must also be defective for other reasons not 
connected with GTK+.

Chris




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