Function pointer and Member function pointer usage?

This is a discussion on Function pointer and Member function pointer usage? within the C++ Programming forums, part of the General Programming Boards category; When should I use function pointer and member function pointer. Till date I have done all my programming without noticing ...

  1. #1
    Registered User
    Join Date
    Oct 2011
    Posts
    48

    Function pointer and Member function pointer usage?

    When should I use function pointer and member function pointer.

    Till date I have done all my programming without noticing any need of these two. Then when it is actually used?

    And what is the need of Callback function. (I asked this question in case you were going to answer Callback function).
    Last edited by freiza; 05-28-2012 at 06:20 PM.

  2. #2
    C++ Witch laserlight's Avatar
    Join Date
    Oct 2003
    Location
    Singapore
    Posts
    21,424
    Quote Originally Posted by freiza
    When should I use function pointer and member function pointer.

    Till date I have done all my programming without noticing any need of these two. Then when it is actually used?
    I did a quick search of the Web for "C++ member function pointer". It was not too hard to find articles like Pointers to C++ Member Functions.

    Quote Originally Posted by freiza
    And what is the need of Callback function. (I asked this question in case you were going to answer Callback function).
    Search the Web for "callback function". In C++, some examples include those generic algorithms from <algorithm> that take a function pointer or function object as a predicate or to perform some special action.
    C + C++ Compiler: MinGW port of GCC
    Version Control System: Bazaar

    Look up a C++ Reference and learn How To Ask Questions The Smart Way

  3. #3
    Registered User
    Join Date
    Oct 2011
    Posts
    48
    Still confused. I mean instead of using function pointers, why we cannot simply call the function with the objects.

  4. #4
    C++ Witch laserlight's Avatar
    Join Date
    Oct 2003
    Location
    Singapore
    Posts
    21,424
    Quote Originally Posted by freiza
    I mean instead of using function pointers, why we cannot simply call the function with the objects.
    The idea is to pass a function f as an argument to another function g such that g can call f. The reason why g cannot call f directly is that f may actually be functions f1, f2, f3, ..., fN, as the case may be.
    C + C++ Compiler: MinGW port of GCC
    Version Control System: Bazaar

    Look up a C++ Reference and learn How To Ask Questions The Smart Way

  5. #5
    Registered User
    Join Date
    May 2012
    Location
    Stoke, England
    Posts
    1
    And what is the need of Callback function.
    They are typically used as handlers. Handlers are functions which "handle" events when they arise. When programming with signals, callbacks are used to handle the signals that the OS dispatches. For example, say the OS dispatched a SIGSEGV (Segmentation Violation) signal, I would register a callback function to handle that signal.

    Wazzak

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. function pointer inner member function of class C++
    By PuKa in forum C++ Programming
    Replies: 3
    Last Post: 11-14-2011, 12:48 AM
  2. Pointer to member function?
    By C+/- in forum C++ Programming
    Replies: 9
    Last Post: 05-13-2007, 07:58 AM
  3. Replies: 3
    Last Post: 07-23-2006, 01:09 PM
  4. how to use a member function inside a function pointer?
    By mickey in forum C++ Programming
    Replies: 6
    Last Post: 10-17-2002, 04:27 AM
  5. Pointer to member function as callback function
    By ninebit in forum C++ Programming
    Replies: 10
    Last Post: 03-01-2002, 04:52 AM

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21