文档介绍:The Function Pointer Tutorials
Introduction to C and C++ Function Pointers, Callbacks and Functors
written by Lars Haendel
January 2003, Dortmund, Germany
email: ******@
version
Copyright (c) 2000-2003 by Lars Haendel. Permission is granted to copy,
distribute and/or modify this document under the terms of the GNU Free
Documentation License, Version or any later version published by the
Free Software Foundation; with no Invariant Sections, with the Front-
Cover Text being the text from the title up to the table of contents, and
with no Back-Cover Texts. A copy of the license can be obtained from
.
Be aware that there may be a newer version of this document! Check
/e for the latest release. If you want to
distribute this document, I suggest you to link to the URL above to prevent
spreading of outdated versions.
You may also download the source code of the examples at
/ . The example code is free software
under the terms of the GNU General Public License.
Contents
1 Introduction to Function Pointers 2
What is a Function Pointer ? . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 2
Introductory Example or How to Replace a Switch-Statement . . . . . . . . . . . . . . . . . . . . 2
2 The Syntax of C and C++ Function Pointers 3
Define a Function Pointer . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 3
Calling Convention . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 3
Assign an Address to a Function Pointer . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 4
Function Pointers . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 4
Calling a Function using a Function Pointer . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 4
How to Pass a Function Pointer as an Argument ? . . . . . . . . . . . . .