Path: utzoo!news-server.csri.toronto.edu!cs.utexas.edu!usc!snorkelwacker.mit.edu!bloom-beacon!dont-send-mail-to-path-lines From: XITIJSCH@DDATHD21.BITNET Newsgroups: comp.windows.x Subject: Re: C++ and X: Member-Functions as Callbacks Message-ID: <9103111132.AA29489@expo.lcs.mit.edu> Date: 11 Mar 91 15:13:55 GMT Sender: daemon@athena.mit.edu (Mr Background) Organization: The Internet Lines: 40 X-Unparsable-Date: Mon, 11 Mar 91 10:37:00 MEZ Try the following (I assume you use an ANSI C preprocessor): --- This goes into a general header file: #define use_as_callback(Class, foo) \ void foo##_dispatch(Widget w, Class *object, caddr_t call_data) \ { \ object->foo(w, 0, call_data); \ } #define Cpp_callback(foo) foo##_dispatch --- This is your C++ code: class Name_of_class { ... void do_it(Widget w, caddr_t client_data, caddr_t call_data); ... }; use_as_callback(Name_of_class, do_it); .. Name_of_class object; ... XtAddCallback(w, Cpp_callback(do_it), &object); or, if you use Motif, you will register Cpp_callback(do_it) and pass &object via an UIL identifier, etc. There remains a problem with this approach: You cannot pass client_data -- but perhaps you may attach it as userdata to the widget. -- Joachim Schrod Technical University of Darmstadt