Path: utzoo!utgpu!news-server.csri.toronto.edu!cs.utexas.edu!wuarchive!uunet!tcs!nujoizey!gwu From: gwu@nujoizey.Berkeley.EDU (George Wu) Newsgroups: comp.lang.c++ Subject: Re: Again: Pointer to methods ? Keywords: Pointers to methods Message-ID: <958@tcs.tcs.com> Date: 14 Aug 90 19:00:39 GMT References: <2292@zgdvda.zgdvda.uucp> Sender: usenet@tcs.com Reply-To: gwu@nujoizey.Berkeley.EDU (George Wu) Lines: 44 In article <2292@zgdvda.zgdvda.uucp>, dingelde@viktoria.grz (Dennis Dingeldein) writes: |> // class Menu provides a pulldown functionality |> class Menu { |> |> public: |> SetPointer( ???? ); // the method ???? will be called if any |> // Menu Entry is selected (not senseful, I know) |> Start(); // display and start the interaction with the menu |> ... |> }; |> |> // class Circle is unknown class, here only for the example visible |> // it provides the output behaviour of a circle. |> class Circle { |> |> public: |> Draw(); // displays the circle |> }; |> |> // main shows a menu and draws the circle on selection |> main() { |> Menu MyMenu( "Draw Circle" ); |> Circle MyCircle( ... ); |> |> MyMenu.SetPointer( MyCircle::Draw( ... ) ); |> |> // If the User selects an entry , the circle is drawn! |> Menu.Start(); |> } We do similar stuff in some of our code. For us, class Circle and all similar classes inherit from a base class, say class Callable. Then the Menu::SetPointer() argument is just a pointer to a member function of class Callable. The parameters passed to the to be invoked later function are of course fixed. 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