|
-
March 3rd, 2008, 10:40 PM
#2
Re: Function pointers...I don't know what they are
The problem with function pointers is that in toy cases they seem a bit pointless. You only realize how useful they are once you get into more complex stuff.
In generic terms:
1) Define a function pointer func that matches the signatures of functions f and g.
2) Read input. Depending on input, assign either f or g to func.
3) Call whichever function func points to by dereferencing func.
Let's say you have 10 places where f or g need to be called. The "normal" way, you'd need 10 if statements. With a function pointer, you only need 1 (to set the pointer).
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|