Function pointer

This is a discussion on Function pointer within the C++ Programming forums, part of the General Programming Boards category; Hello everyone, In the following statements, Code: template <class R, class T> class mem_fun_t : public unary_function <T*, R> { ...

  1. #1
    Registered User
    Join Date
    May 2006
    Posts
    1,579

    Function pointer

    Hello everyone,


    In the following statements,

    Code:
    template <class R, class T> class mem_fun_t : public unary_function <T*, R>
    
    {
    
    R (T::*pmf)()
    ...
    }
    1. I think pmf is a type of function pointer, the return type of the function is R and the function is a member function of type (class) T. Is my understanding correct?

    2. If yes, what is the parameter list of the function? Empty parameter list?

    3. I doubt whether it is useful to define a function pointer with empty parameter list -- too restricted.


    thanks in advance,
    George

  2. #2
    C++まいる!Cをこわせ!
    Join Date
    Oct 2007
    Posts
    23,029
    Quote Originally Posted by George2 View Post
    1. I think pmf is a type of function pointer, the return type of the function is R and the function is a member function of type (class) T. Is my understanding correct?
    That first statement is weird. There must be some missing code.
    Could it be some kind of declaration of function pointer? Still, it's missing ; at the end.

    2. If yes, what is the parameter list of the function? Empty parameter list?
    Yes.

    3. I doubt whether it is useful to define a function pointer with empty parameter list -- too restricted.
    Not always. You can use events for example, where you call back saying an event has finished or some such. Also useful when using dynamic linking of dlls. You get a function address dynamically from a dll, and call it using a function pointer.
    Sometimes these functions don't take any arguments.
    Quote Originally Posted by Adak View Post
    io.h certainly IS included in some modern compilers. It is no longer part of the standard for C, but it is nevertheless, included in the very latest Pelles C versions.
    Quote Originally Posted by Salem View Post
    You mean it's included as a crutch to help ancient programmers limp along without them having to relearn too much.

    Outside of your DOS world, your header file is meaningless.

  3. #3
    Kernel hacker
    Join Date
    Jul 2007
    Location
    Farncombe, Surrey, England
    Posts
    15,677
    Quote Originally Posted by George2 View Post
    Hello everyone,


    In the following statements,

    Code:
    template <class R, class T> class mem_fun_t : public unary_function <T*, R>
    
    {
    
    R (T::*pmf)()
    ...
    }
    1. I think pmf is a type of function pointer, the return type of the function is R and the function is a member function of type (class) T. Is my understanding correct?
    Yes.

    2. If yes, what is the parameter list of the function? Empty parameter list?
    Correct.
    3. I doubt whether it is useful to define a function pointer with empty parameter list -- too restricted.
    Yes, it's restricted in the sense that you can't pass in any parameters.

    But some functions are fine without parameters. It's a typical case of "right tool for the job" - no point in adding parameters to a function if you don't actually need any. For example, this function may be to fetch an object R out of the T class, which only holds ONE R object - in which case, it's perfectly fine to do that without any parameters. Without a wider scope to understand the meaning of the code, it's impossible to say if it's "too restricted" or "just right".

    --
    Mats
    Compilers can produce warnings - make the compiler programmers happy: Use them!
    Please don't PM me for help - and no, I don't do help over instant messengers.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. sorting number
    By Leslie in forum C Programming
    Replies: 8
    Last Post: 05-20-2009, 05:23 AM
  2. <Gulp>
    By kryptkat in forum Windows Programming
    Replies: 7
    Last Post: 01-14-2006, 01:03 PM
  3. Function Pointer help
    By Skydt in forum C Programming
    Replies: 5
    Last Post: 12-02-2005, 09:13 AM
  4. pointers
    By InvariantLoop in forum C Programming
    Replies: 13
    Last Post: 02-04-2005, 09:32 AM
  5. Interface Question
    By smog890 in forum C Programming
    Replies: 11
    Last Post: 06-03-2002, 06:06 PM

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