Computer Forums

Member Login

Remember Me? Sign Up! | Forgot Password
 
Slogan
 
Closed Thread
Old 03-19-2006, 06:34 AM   #1 (permalink)
 
True Techie

Join Date: Nov 2005

Posts: 115

i_learn

Default Pointers to functions

first off....what is its use....where will i ever need a pointer to a fucntion . now lets say i awnt to put it in a class.....where do i define the pointer to a member fucntion? and how do i call it.
i_learn is offline  
Old 03-19-2006, 07:06 AM   #2 (permalink)
 
Ultra Techie

Join Date: Jul 2005

Posts: 530

TheHeadFL

Send a message via AIM to TheHeadFL
Default

Well... pointers to functions are used in 'callback' functions. Wherein another section of code has to make a call backwards to some notifier function that is not neccesarily known at design time.

This is used for event driven programming. You can have the OS 'call back' a function in your program that you specify whenever a certain action happens. (e.g. data is received on a TCP/IP socket)

Also, to point to a member function, you basically need to get a pointer to the object containing the function as well. So you call the callback function pointer like any other function pointer, but you also call (MyObjectType*)(my_objectPointer)->FunctionPointer();

Thats how its done in C++.
__________________
Desktop machine: 2 x Opteron 246, Asus K8N-DL, 2GB PC3200 ECC Reg., XFX GeForce 6600GT, 74gb WD Raptor, 2 x 19\" LCDs, Windows XP x64
Server machine: Intel P4 3.0GHz 2MB EM64T, ECS i865pe, 1GB PC3200, 36gb WD Raptor, Windows Server 2003
Laptop: Dell Inspiron 9100 (Intel P4 3.2GHz 1MB Prescott, i865pe, 512MB PC3200, Mobility Radeon 9700, DVD+R/DL Burner), Windows XP
Linux: P3 450Mhz, 386MB ram, Slackware 10.1 (Running mySQL/Apache)
TheHeadFL is offline  
Old 03-19-2006, 12:26 PM   #3 (permalink)
 
True Techie

Join Date: Nov 2005

Posts: 115

i_learn

Default

i dont really get what u just said......what can i do that i cant do with just a function. i could call it again if i wanted to right?
and use this example...
class test
{
public:
void func();
//do i put the function pointers signature here?
};

void main()
{
//or do i put it here?
//and how do i call it
test (*x)();
}
i_learn is offline  
 
Closed Thread

Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On