Xref: utzoo comp.lang.c++:5140 comp.windows.x:14436 Path: utzoo!attcan!utgpu!jarvis.csri.toronto.edu!mailrus!uwm.edu!gem.mps.ohio-state.edu!tut.cis.ohio-state.edu!att!cbnewsl!dog From: dog@cbnewsl.ATT.COM (edward.n.schiebel) Newsgroups: comp.lang.c++,comp.windows.x Subject: Re: using X11 with C++ callbacks Message-ID: <2374@cbnewsl.ATT.COM> Date: 20 Oct 89 11:47:04 GMT References: <640@sunquest.UUCP> Organization: AT&T Bell Laboratories Lines: 36 From article <640@sunquest.UUCP>, by francis@sunquest.UUCP (Francis Sullivan): > I would like to be able to use C++ callbacks in X11. Since this is not > supported, I'm trying to come up with a simple method to simulate this. > For now I just write a C wrapper that calls the correct C++ routine, but > I get the feeling that there is an easier way. [...code deleted...] I have implemented one solution in SunView, but it seems to be the same problem. First, I have an abstract base class class dispatchable { public: virtual int doit() = 0; }; the application derives specific classes from this one to do the program's stuff. Now, each Button, Menu_item etc. is given a dispatchable* (either through some client data mechanism or by creating a class Button which encapsulates the X/SunView implementation). When a button is pressed, grab its dispatchable* and call doit(). As an aside, I have noticed to get anything like this to work well takes a lot more time up front providing support classes etc., but in the end, the application is so much easier to write. Hope this is useful, it has worked for me. Ed Schiebel AT&T Bell Laboratories dog@vila.att.com 201-386-3416