Path: utzoo!attcan!utgpu!jarvis.csri.toronto.edu!clyde.concordia.ca!uunet!pilchuck!dataio!gtenmc!fst From: fst@gtenmc.UUCP (Fariborz "Skip" Tavakkolian) Newsgroups: comp.lang.c++ Subject: Re: Passing function pointers in C++ Message-ID: <306@gtenmc.UUCP> Date: 10 Dec 89 20:12:30 GMT References: <5115.25805AED@urchin.fidonet.org> Reply-To: fst@gtenmc.UUCP (Fariborz Skip Tavakkolian) Organization: GTE Telecon, Inc. Bothell, WA Lines: 56 In article <5115.25805AED@urchin.fidonet.org> Roy.Browning@f506.n106.z1.fidonet.org (Roy Browning) writes: > > From: abbott@aerospace.aero.org (Russell J. Abbott) > > In article <32106@watmath.waterloo.edu> gjditchfield@watmsg.waterloo.edu > > > ... In practice, in C++, wouldn't it be simpler to pass a comparison > > >function as an argument to the sort() function? > > Can you really do that in C++? What would the declarations look like? [deleted] >Personally I believe that deriving different sorting methods from the base >class is much cleaner and more in line with OOP. I have a similar question, or it may be a major confusion in my part. Say I have a class like this: class genericField { protected: int length, line, column; // here I want something similar to the following three int (genericField::*before)(); int (genericField::*verify)(); int (genericField::*after)(); public: genericField(int len, int ln, int col); ~genericField(); virtual int edit(cursesWindow& w); void setBefore(int (genericField::*user_before_function)()); ... }; class dateField : public genericField { ... }; class integerField : public genericField { ... }; // and so on ... Generally speaking the ``before'' is to be invoked just before editing is attempted. For example suppose we have integerField customer_id; integerField inventory_code; The ``before'' function for customer_id may make a menu of all allowed customer ids, and the ``before'' function for inventory_code will make a list of valid inventory items (from a database for example). As can be demonstrated each instance of the integerField class may need a different ``before'' function. Question: how to do this so that a programmer will not need to derive a new class for each occurrence of a field (i.e. not using virtuals)? Many thanks Skip -- ---------------------------------------------------------------------------- Fariborz "Skip" Tavakkolian -of- Automated Cellular Engineering Currently consulting -at- GTE Telecom, Inc. Bothell, Wa Mail: tiny1!fst@mcgp1 -or- fst@gtenmc