需要帮助解决编译器错误:错误:从“ int”到“ giocondition”的无效转换

StackOverflow https://stackoverflow.com/questions/2521699

  •  22-09-2019
  •  | 
  •  

我有一个使用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/glib-io-channels.html, ,说我只需要包括在内。

您能告诉我如何解决我的错误吗?

我能想到的一件事是我在CPP文件中这样做。但是g_io_add_watch是交流功能吗?

感谢您的任何帮助。我已经花了几个小时,但没有到达任何地方。

有帮助吗?

解决方案

你可以施放

(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);
}

其他提示

我猜它正在标记错误,因为您必须使用严格打字的CPP编译器。

c编译器的范围,这主要是警告。

您可以将其键入((giocondition)g_io_in | g_io_hup)或创建类型Giocondition的变量并将其传递给函数。

许可以下: CC-BY-SA归因
不隶属于 StackOverflow
scroll top