C Board  

Go Back   C Board > General Programming Boards > C++ Programming

Reply
 
LinkBack Thread Tools Display Modes
Old 03-04-2008, 11:01 PM   #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
ting is offline   Reply With Quote
Old 03-04-2008, 11:12 PM   #2
Just Lurking
 
Dave_Sinkula's Avatar
 
Join Date: Oct 2002
Posts: 5,005
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.*
Dave_Sinkula is offline   Reply With Quote
Old 03-04-2008, 11:18 PM   #3
C++ Witch
 
laserlight's Avatar
 
Join Date: Oct 2003
Location: Singapore
Posts: 11,296
Quote:
1) Can function pointer point to a static function?
I do not see why not, so I say yes.

Quote:
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.

Quote:
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).

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

Quote:
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
Build + Version Control System: SCons + Bazaar

Look up a C/C++ Reference and learn How To Ask Questions The Smart Way
laserlight is offline   Reply With Quote
Old 03-04-2008, 11:50 PM   #4
CSharpener
 
vart's Avatar
 
Join Date: Oct 2006
Posts: 5,311
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.
__________________
If I have eight hours for cutting wood, I spend six sharpening my axe.
vart is offline   Reply With Quote
Old 03-05-2008, 02:36 AM   #5
Registered User
 
Join Date: Nov 2006
Posts: 510
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
pheres is offline   Reply With Quote
Reply

Thread Tools
Display Modes

Forum Jump

Similar Threads
Thread Thread Starter Forum Replies Last Post
Which Library Files for these unreferenced functions? lehe C++ Programming 3 01-31-2009 10:30 PM
Compiling sample DarkGDK Program Phyxashun Game Programming 6 01-27-2009 03:07 AM
Problem in compiling targa2.c: error: field `ip' has incomplete type.. Moony C Programming 0 03-20-2008 07:59 AM
Calling a Thread with a Function Pointer. ScrollMaster Windows Programming 6 06-10-2006 08:56 AM
structure vs class sana C++ Programming 13 12-02-2002 07:18 AM


All times are GMT -6. The time now is 05:06 PM.


Powered by vBulletin® Version 3.8.1
Copyright ©2000 - 2010, Jelsoft Enterprises Ltd.
Search Engine Optimization by vBSEO 3.3.2

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