Path: utzoo!attcan!uunet!tut.cis.ohio-state.edu!att!dptg!ulysses!andante!alice!garry From: garry@alice.UUCP (garry hodgson) Newsgroups: comp.lang.c++ Subject: Re: What are pointers-to-members good for? Keywords: member pointers Message-ID: <11329@alice.UUCP> Date: 13 Sep 90 19:17:52 GMT References: <1990Sep4.225920.14917@agate.berkeley.edu> Organization: AT&T Bell Laboratories, Murray Hill NJ Lines: 29 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. Here are 2 small but useful examples that I use. I use a Generic list class, called a Bunch, which has an Invoke() member function which invokes the specified member function on each of its elements. Thus, for example, in the Bunchimplement macro in my Bunch.h, I might have void Bunch(type)::Print() { Invoke( &type::Print ); } You could use this same approach to build mapping functions like those in Lisp. In InterViews applications, I have a generic Popup menu class. Associated with each menu entry is a callback procedure, which is a member function of the class which owns the menu, and thus has access to whatever it needs to implement the function. garry hodgson