我有一个使用 GIO 的简单 cpp 文件。我已经删除了所有内容以显示我的编译错误:
这是我得到的错误:
My.cpp:16: error: invalid conversion from ‘int’ to ‘GIOCondition’
make[2]: *** [My.o] Error 1
完整文件如下:
#include <glib.h>
static gboolean
read_socket (GIOChannel *gio, GIOCondition condition, gpointer data)
{
return false;
}
void createGIOChannel() {
GIOChannel* gioChannel = g_io_channel_unix_new(0);
// the following is the line causing the error:
g_io_add_watch(gioChannel, G_IO_IN|G_IO_HUP, read_socket, NULL);
}
我看过其他使用 gio 的例子,我也在调用 G_IO_IN|G_IO_HUP 方面做同样的事情。 和文档 http://www.gtk.org/api/2.6/glib/glib-IO-Channels.html , 说我只需要包括 ,我做到了。
你能告诉我如何解决我的错误吗?
我能想到的一件事是我在一个 cpp 文件中这样做。但是 g_io_add_watch 是一个 c 函数吗?
感谢您的帮助。我在这上面花了几个小时,但一无所获。
最佳答案
你可以施放它
(GIOCondition) G_IO_IN|G_IO_HUP
或
void createGIOChannel() {
GIOChannel* gioChannel = g_io_channel_unix_new(0);
// the following is the line causing the error:
GIOCondition cond = G_IO_IN|G_IO_HUP;
g_io_add_watch(gioChannel, cond , read_socket, NULL);
}
关于c++ - 需要帮助解决编译器错误 : error: invalid conversion from ‘int’ to ‘GIOCondition’ ,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/2521699/