title: Gtk+ g_signal_connect() and C++ lambda results in "invalid cast" errors
body: <p>I would like to use lambdas with <a href="https://developer.gnome.org/gobject/stable/gobject-Signals.html#g-signal-connect" rel="nofollow noreferrer"><code>g_signal_connect()</code></a> from Gtk+. 
   Traditionally works like this to setup a callback function:</p>
  
  <pre><code>#include &lt;gtk/gtk.h&gt;
  #include &lt;iostream&gt;
  
  void my_callback(GtkApplication *app, gpointer user_data)
  {
      std::cout &lt;&lt; "test1" &lt;&lt; std::endl;
  }
  
  void test1()
  {
      GtkApplication *app = gtk_application_new(nullptr, G_APPLICATION_NON_UNIQUE);
      void * data = nullptr; // simple example
      g_signal_connect(app, "activate", G_CALLBACK(my_callback), data);
  }
  </code></pre>
  
  <p>Above test is compiled with <code>g++ $(pkg-config --cflags --libs gtk+-3.0) test.cpp</code> to get the necessary GTK+-3.0 definitions.</p>
  
  <p>In attempting to convert <code>my_callback1()</code> to a lambda, I tried variations of this:</p>
  
  <pre><code>void test2()
  {
      GtkApplication *app = gtk_application_new(nullptr, G_APPLICATION_NON_UNIQUE);
      void * data = nullptr; // simple example
  
      // use lambda instead of call to explicit function
      g_signal_connect(app, "activate",
          G_CALLBACK(
              [](GtkApplication *application, gpointer user_data)
              {
                  std::cout &lt;&lt; "test2" &lt;&lt; std::endl;
              }
          ), data);
  }
  </code></pre>
  
  <p>The <code>test2()</code> code above produces the following compile error:</p>
  
  <pre><code>/usr/include/glib-2.0/gobject/gclosure.h:70:41: error: invalid cast
  from type ‘test2()::&lt;lambda(GtkApplication*, gpointer)&gt;’
  to type ‘GCallback {aka void (*)()}’
  </code></pre>
  
  <p>Is there a way to specify a C++ lambda as the callback function?  I don't understand what is needed to fix this "invalid cast".</p>