extern "C", C++, and GTK+ callbacks.



Some compilers [1], correctly complain when we use a static member
function as a GTK+ callback. GTK+ expects (and declares) an "extern C"
pointer-to-function, but our static member methods are not declared as
"extern C".

Unfortunately, it seems that static member methods can never be extern
"C". g++ does not allow anything like this:

class something
{
public:
  extern "C" void function_one(); 

  extern "C"
  {
    void function_one();
  }
}


So we have to move the callbacks outside of the class, and declare them
as friend functions so that they can access the class:

extern "C"
{
  void Something_function_one();
}

class something
{
public:
  friend void function_one();

protected:
  void something_protected();
}

void Something_function_one()
{
  //Get something somehow.
  //Use it:
  something.something_protected();
}
 

This is annoying. Does anyone have a simpler suggestion?


[1] SUN Forte issues warnings. MipsPro issues errors, stopping the
compilation.

-- 
Murray Cumming
murrayc murrayc com
www.murrayc.com
www.openismus.com




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