What is a virtual function pointer?

This is a discussion on What is a virtual function pointer? within the C++ Programming forums, part of the General Programming Boards category; I think i understand "function pointer": a pointer that points to a function. Function pointer-questions: 1) Can function pointer point ...

  1. #1
    Registered User
    Join Date
    Mar 2008
    Location
    vancouver bc
    Posts
    28

    What is a virtual function pointer?

    I think i understand "function pointer": a pointer that points to a function.

    Function pointer-questions:
    1) Can function pointer point to a static function?
    2) Can function pointer point to a member function?
    3) Can function pointer point to a virtual member function?
    4) Why use function pointer? can i just use if/then to avoid the use of function pointer completely? (because i really am afraid of using function pointer)

    generic-questions:
    1) how to use ' extern "C" ' ? is it necessary ?
    2) Why do we need multiple inheritance?

    --TING

  2. #2
    Just Lurking Dave_Sinkula's Avatar
    Join Date
    Oct 2002
    Posts
    5,006
    You may find some of the answers here:
    http://www.google.com/search?q=funct....parashift.com
    7. It is easier to write an incorrect program than understand a correct one.
    40. There are two ways to write error-free programs; only the third one works.*

  3. #3
    C++ Witch laserlight's Avatar
    Join Date
    Oct 2003
    Location
    Singapore
    Posts
    22,271
    1) Can function pointer point to a static function?
    I do not see why not, so I say yes.

    2) Can function pointer point to a member function?
    3) Can function pointer point to a virtual member function?
    There are pointers to member functions, but they are not really function pointers.

    4) Why use function pointer? can i just use if/then to avoid the use of function pointer completely? (because i really am afraid of using function pointer)
    Take for example qsort(). You certainly cannot just use if statements to replace passing the comparator function as a function pointer. The std::sort() generic algorithm takes a comparator that behaves like a function: so it could be a function pointer or a function object. In that sense, you can avoid function pointers in such cases by using function objects (possibly with template code).

    1) how to use ' extern "C" ' ? is it necessary ?
    Read the FAQ: How to mix C and C++

    2) Why do we need multiple inheritance?
    We do not need multiple inheritance. That said, read Inheritance - multiple and virtual inheritance
    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

  4. #4
    CSharpener vart's Avatar
    Join Date
    Oct 2006
    Location
    Rishon LeZion, Israel
    Posts
    6,484
    You have to use function pointers to call some function in exe from dll - you cannot link directly, because dll does not knows about your exe...

    Look at any win32 API that uses CallBack functions.
    The first 90% of a project takes 90% of the time,
    the last 10% takes the other 90% of the time.

  5. #5
    Registered User
    Join Date
    Nov 2006
    Posts
    519
    Quote Originally Posted by vart View Post
    You have to use function pointers to call some function in exe from dll - you cannot link directly, because dll does not knows about your exe...
    You can link, I do it all the time. For plugin systems for example it could be useful. For code modularizing/reusing it isn't

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Replies: 4
    Last Post: 05-13-2011, 09:28 AM
  2. Compiling sample DarkGDK Program
    By Phyxashun in forum Game Programming
    Replies: 6
    Last Post: 01-27-2009, 03:07 AM
  3. Replies: 0
    Last Post: 03-20-2008, 08:59 AM
  4. Calling a Thread with a Function Pointer.
    By ScrollMaster in forum Windows Programming
    Replies: 6
    Last Post: 06-10-2006, 09:56 AM
  5. structure vs class
    By sana in forum C++ Programming
    Replies: 13
    Last Post: 12-02-2002, 07:18 AM

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