Path: utzoo!attcan!uunet!wuarchive!zaphod.mps.ohio-state.edu!van-bc!ubc-cs!news-server.csri.toronto.edu!clyde.concordia.ca!s3!robert From: robert@ireq.hydro.qc.ca (R.Meunier 8516) Newsgroups: comp.lang.c++ Subject: Pointer to function Message-ID: <3194@s3.ireq.hydro.qc.ca> Date: 1 Oct 90 18:08:01 GMT Sender: root@s3.ireq.hydro.qc.ca Reply-To: robert@ireq.hydro.qc.ca () Organization: IREQ, Hydro-Quebec Lines: 150 I'm trying to implement a stack objet with ptr to function as members. But i can't go through the compiler (SUN C++) Here is a part of the code, can someone point me out what is wrong. -------------------------------------------------------------------- #include class ST { void *data; void (*ptrFct)(void *); public: ST(void *, void (*)(void *)); void exec(); }; ST::ST(void *d, void (*ptr)(void *)) { data = d; ptrFct = ptr; } void ST::exec() { (*ptrFct)(data); } void foo1(int *a) { *a += 1; } void foo2(float *a) { *a += 1; } main() { int aa=10; float bb=100; void foo1(int *); void foo2(float *); ST a(&aa,foo1); ST b(&bb,foo2); a.exec(); a.exec(); } -------------------------------------------------------------------- I get those error message from the compiler: "p1.cc", line 44: error: bad argument 2 type for ST::ST(): void (*)(int *) ( void (*)(void *) expected) "p1.cc", line 45: error: bad argument 2 type for ST::ST(): void (*)(float *) ( void (*)(void *) expected) so i have not define the parameter by putting (...) like that -------------------------------------------------------------------- #include class ST { void *data; void (*ptrFct)(...); public: ST(void *, void (*)(...)); void exec(); }; ST::ST(void *d, void (*ptr)(...)) { data = d; ptrFct = ptr; } void ST::exec() { (*ptrFct)(data); } void foo1(int *a) { *a += 1; } void foo2(float *a) { *a += 1; } main() { int aa=10; float bb=100; void foo1(...); void foo2(...); ST a(&aa,foo1); ST b(&bb,foo2); a.exec(); a.exec(); } -------------------------------------------------------------------- With that code, i get ld: Undefined symbol _foo1() _foo2() because the compiler is trying to overload foo1 and foo2 since the parameter do not match. What should i do? P.S. In case you are wondering what i am trying to do, i am implemanting a small task library that will collect ptr to data and ptr to function and execute them later. The function are always of the form: Function(DATA *ptr) { } with function and DATA undefined by the task manager (declare as void *) -- ----------------------------------------------------------------------- Robert Meunier Institut de Recherche d'Hydro-Quebec Ingenieur 1800 Montee Ste-Julie, Varennes Internet: robert@ireq.hydro.qc.ca Qc, Canada, J3X 1S1