Thread: Function pointer and Member function pointer usage?

  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
    28,412
    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.
    Quote Originally Posted by Bjarne Stroustrup (2000-10-14)
    I get maybe two dozen requests for help with some sort of programming or design problem every day. Most have more sense than to send me hundreds of lines of code. If they do, I ask them to find the smallest example that exhibits the problem and send me that. Mostly, they then find the error themselves. "Finding the smallest program that demonstrates the error" is a powerful debugging tool.
    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
    28,412
    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.
    Quote Originally Posted by Bjarne Stroustrup (2000-10-14)
    I get maybe two dozen requests for help with some sort of programming or design problem every day. Most have more sense than to send me hundreds of lines of code. If they do, I ask them to find the smallest example that exhibits the problem and send me that. Mostly, they then find the error themselves. "Finding the smallest program that demonstrates the error" is a powerful debugging tool.
    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, 01: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, 05:52 AM