我有一个使用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函数吗?
感谢您的帮助。我花了好几个小时但却没有到达任何地方。
答案 0 :(得分:1)
答案 1 :(得分:0)
我想它会标记错误,因为你必须使用一个严格的类型检查的CPP编译器。
包含C编译器,应该主要是警告。
您可以对其进行类型转换((GIOCondition)G_IO_IN | G_IO_HUP)或创建GIOCondition类型的变量并将其传递给该函数。