简体   繁体   English

将结构传递给回调函数

[英]Passing a struct to a callback function

I'm trying to pass a struct to a callback function that runs when the combobox is changed, here's my code: 我试图将结构传递给在更改组合框时运行的回调函数,这是我的代码:

static struct parameters changed_set_parameters;

changed_set_parameters.set_combo = set_combo;

gtk_signal_connect (GTK_OBJECT (set_combo), "changed",GTK_SIGNAL_FUNC(set_changed), &changed_set_parameters);

Here's the function: 功能如下:

void set_changed(GtkDialog *dialog, gint response_id, gpointer callback_params) {
    g_print ("%s\n",gtk_combo_box_text_get_active_text ((GtkComboBoxText *)((struct parameters *) callback_params)->set_combo));
}

Here's what I get: 这是我得到的:

gtk_signal_handlers.h:7:98: error: dereferencing pointer to incomplete type
       g_print ("%s\n",gtk_combo_box_text_get_active_text ((GtkComboBoxText *)((struct parameters *) callback_params)->set_combo));

I have almost the same code in another application and it's running just fine 我在另一个应用程序中具有几乎相同的代码,并且运行正常

error: dereferencing pointer to incomplete type

这里的解除引用运算符->时,解除引用的指针是((struct parameters *) callback_params)其类型是struct parameters *set_combo是其成员的struct parameters ,从而定义struct parameters必须超出范围在这里。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM