Re: sigc::ptr_fun() compiler error



Ron Lockwood-Childs a écrit :

Hello,

I get an error when trying to compile the following code:

test.h
------
#include <libglademm/xml.h>
#include <gtkmm>
#include <iostream>

class Test
{
  Glib::RefPtr<Gnome::Glade::Xml> refXml;
  Gtk::Window *pMWindow;
  void on_quit_activate() { if (pMWindow) pMWindow->hide(); }
public:
  Test( int argc, char **argv, char *glade_path );
};

test.cc
-------
#include <libglademm/xml.h>
#include <gtkmm>
#include <iostream>
#include "test.h"

Test::Test( int argc, char **argv, char *glade_path )
{
  try
  {
    refXml = Gnome::Glade::Xml::create( glade_path );
  }
  catch(const Gnome::Glade::XmlError& ex)
  {
    std::cerr << ex.what() << std::endl;
    exit( 1 );
  }

  refXml->get_widget("mainwindow", pMWindow);
  if (pMWindow)
  {
      Gtk::MenuItem* pMenuItem = 0;
      refXml->get_widget("menu_file_quit", pMenuItem);
      if(pMenuItem)
      {
        pMenuItem->signal_activate().connect(
          sigc::ptr_fun( &Test::on_quit_activate ) );
      }
  }
}

int main( argc, argv )
{
  Test testDialog = new Test( argc, argv, "test.glade" );
  return 0;
}

---------
(if I've made copy-paste errors, FWIW the actual code doesn't get syntax errors..)

Finally, when I attempt compilation, this is what I get:

$ g++ test.cc -o test `pkg-config gtkmm-2.4 --cflags --libs` -lglademm-2.4
test.cc: In constructor `Test::Test(int, char**, char*)':
test.cc: error: no matching function for call to `ptr_fun(void (Test::*)())'

This was taken from the tutorial, except that now I'm attempting to put the UI code into its own class. It gives me no hint on why it can't find the function. If I do anything to the function pointer, such as:
sigc::ptr_fun(&(Test::on_quit_activate))
or
sigc::ptr_fun(&(this->on_quit_activate))
I get the same error, with another complaint regarding ANSI C++ and pointers to non-static member functions. This signal handler must be a member function, since it accesses private data.

Anyone seen this or similar errors & can offer help?  I'd appreciate it.

--
Ron Lockwood-Childs
_______________________________________________
gtkmm-list mailing list
gtkmm-list gnome org
http://mail.gnome.org/mailman/listinfo/gtkmm-list

try sigc::mem_fun

--
Yann Normand
Sogeti-Transiciel




[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]