Path: utzoo!utgpu!news-server.csri.toronto.edu!mailrus!uunet!tcs!nujoizey!gwu From: gwu@nujoizey.tcs.com (George Wu) Newsgroups: comp.lang.c++ Subject: Re: What are pointers-to-members good for? Keywords: member pointers Message-ID: <1007@tcs.tcs.com> Date: 11 Sep 90 03:44:17 GMT References: <1990Sep4.225920.14917@agate.berkeley.edu> Sender: usenet@tcs.com Reply-To: gwu@nujoizey.tcs.com (George Wu) Organization: Teknekron Communications Systems Lines: 39 In article <1990Sep4.225920.14917@agate.berkeley.edu>, holub@violet.berkeley.edu writes: |> Can anyone give me a realistic example of what pointers to class members |> are good for? I understand how they work and what they do, but all of the |> books I've seen give examples that are too trivial to be useful, and |> every time I try to use them I come up against some structural problem that |> eventually makes me take a different approach. We use such pointers for generic menu item and button classes. For instance, we have a generic button which, when pressed, will call the previously defined function: class Caller { // . . . }; class CbButton { CbButton(const char *label, Caller *object, (Caller::*funcPtr)()); Press() }; where Press() looks something like: CbButton::Press() { (object->*funcPtr)(); } We actually use a generic type for CbButton in order to get the type checking correct. And we use such code in all sorts of places. Sure, it's simple, but it's effective. George ---- George J Wu | gwu@tcs.com or ucbcad!tcs!gwu Software Engineer | 2121 Allston Way, Berkeley, CA, 94704 Teknekron Communications Systems, Inc.| (415) 649-3752