Home › Forums › C Programming › Generic pointer to member functions of a class
- This topic has 3 replies, 2 voices, and was last updated 16 years, 11 months ago by shalizy.
- AuthorPosts
- January 12, 2008 at 1:31 am #2057TanishqParticipant
Hello Folks!!!!
i have one interesting question over here ……….
Is it possible to create a generic pointer (generic pointer to member functions) which can point to all the member functions of a class
Ex : Code: ( cpp )12345678class abc(){<br />int fun1(int a){<br />//Body of fun1<br />}<br />float fun2(float a){<br />//Body of fun2<br />}<br />}; //End of classhere a generic pointer which can hold the address of functions fun1 as well as fun2
Comments will be appreciated.!!!! - January 16, 2008 at 10:29 pm #3314shalizyParticipant
Offcourse man!!!
1234abc obj;<br />abc * ptr= & obj;<br />ptr->fun1();<br />ptr->fun2();Asadullah Ansari
- January 17, 2008 at 11:00 am #3315TanishqParticipant
Assalmaulaikum Asad, This is not wot i wanted… i wanted to have a pointer to a member function and not a pointer to object….
Ex: int (abc:: *ptr)(int );here ptr is an pointer to a member function of the class…
something like this which is very generic and can hold the address of every function of that class.. - January 18, 2008 at 12:09 am #3316shalizyParticipant
walakum salam nadeem bhai!!!
Now you give correct requirement!!!
we can declare a pointer to anf member functions which has any number and any type of arguments. But return type will be same .1int (abc:: *ptr) ( . . .)I did’nt try to take return type as as template. I dont template will woek or not…
- AuthorPosts
- The forum ‘C Programming’ is closed to new topics and replies.