From: jkubicky AT cco DOT caltech DOT edu (Joseph J. Kubicky) Subject: Problem getting pointer to member function - HELP! To: djgpp AT sun DOT soe DOT clarkson DOT edu Date: Wed, 29 Apr 92 2:56:26 PDT Status: O Newsgroups: comp.lang.c++ Subject: Problem with pointer to member function - HELP! Newsgroups: comp.lang.c++ Subject: Problem with pointer to member function - HELP! I'm having a problem with the following piece of code: class Block { protected: char name[MAX_NAME_LEN+1]; int num_inputs; DATA_ID (*input_func[MAX_BLOCK_INPUTS])(); DATA_ID current_output, next_output; public: // Constructor basically just gives the Block a name Block(char *n); // functions for maintaining input-function list (our input link to rest of world) void ClearInputList() { num_inputs = 0; } // clear out input list void AddInput(DATA_ID (*inp)()) { // append an input onto input list if(num_inputs < MAX_BLOCK_INPUTS - 1) input_func[num_inputs++] = inp; } // function that returns data (called by blocks with us as their output) // just returns current_output DATA_ID GetOutput(); // default (virtual) initializer function (called before start of each // new simulation run) virtual int Initialize(); . . }; . . . class SinGen : public Block { int period; int nextiter; DATA_ID magnitude; public: // Overloaded constructor - we define output type based on which is // called SinGen(char *, int, int); SinGen(char *, int, double); Simulate(); Initialize(); }; . . . main() { Printval PV("Print"); SinGen SG("Function Generator", 20, 1.0); PV.AddInput(SG.GetOutput); ^^^^^^^^^^^^^^^^^^^^^^^^^^^ Problem with this line. . . } The problem is with the underlined line. I was hoping that I could use SG.GetOutput just like any other function reference and pass it like a normal pointer to a function, but gcc (djgpp's latest release - 1.06) gives me the following error message: ERR> ... bad argument 0 for function 'Block:AddInput(auto struct DATA_ID(*)())' ERR> (type was struct DATA_ID(class Block::*)()) Clearly, SG.GetOutput isn't a DATA_ID(*)(). I've tried explicitly typing it as such, and the compiler just tells me it can't convert the argument. The line compiles fine if I do something like: DATA_ID test(); PV.AddInput(test); DATA_ID is: typedef struct { char type; union { ... } u; } DATA_ID; Is it even possible to use a reference to a member function in this context? Any help will be appreciated. Jay Kubicky jkubicky AT cco DOT caltech DOT edu