function_pointers

function_pointers - The Function Pointer Tutorials...

Info iconThis preview shows pages 1–2. Sign up to view the full content.

View Full Document Right Arrow Icon

Info iconThis preview has intentionally blurred sections. Sign up to view the full version.

View Full DocumentRight Arrow Icon
This is the end of the preview. Sign up to access the rest of the document.

Unformatted text preview: The Function Pointer Tutorials Introduction to C and C++ Function Pointers, Callbacks and Functors written by Lars Haendel January 2005, Bochum, Germany http://www.newty.de email: Have a look at the web page please version 2.07 Copyright (c) 2000-2005 by Lars Haendel. Permission is granted to copy, distribute and/or modify this document under the terms of the GNU Free Documentation License, Version 1.1 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 http://www.gnu.org . Be aware that there may be a newer version of this document! Check http://www.newty.de/fpt/zip/e fpt.pdf 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 http://www.newty.de/fpt/zip/source.zip . The example code is free soft- ware under the terms of the GNU General Public License. Contents 1 Introduction to Function Pointers 2 1.1 What is a Function Pointer ? . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 2 1.2 Introductory Example or How to Replace a Switch-Statement . . . . . . . . . . . . . . . . . . . . 2 2 The Syntax of C and C++ Function Pointers 3 2.1 Define a Function Pointer . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 3 2.2 Calling Convention . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 3 2.3 Assign an Address to a Function Pointer . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 4 2.4 Comparing Function Pointers . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 4 2.5 Calling a Function using a Function Pointer . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 5 2.6 How to Pass a Function Pointer as an Argument ? . . . . . . . . . . . . . . . . . . . . . . . . . . 5 2.7 How to Return a Function Pointer ? . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 5 2.8 How to Use Arrays of Function Pointers ? . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 6 3 How to Implement Callback Functions in C and C++ 7 3.1 Introduction to the Concept of Callback Functions . . . . . . . . . . . . . . . . . . . . . . . . . . 7 3.2 How to Implement a Callback in C ? . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 8 3.3 Example Code of the Usage of qsort . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 8 3.4 How to Implement a Callback to a static C++ Member Function ? . . . . . . . . . . . . . . . . . 9 3.5 How to Implement a Callback to a non-static C++ Member Function ? . . . . . . . . . . . . . . 9 4 Functors to encapsulate C and C++ Function Pointers 11 4.1 What are Functors ? . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 11What are Functors ?...
View Full Document

Page1 / 13

function_pointers - The Function Pointer Tutorials...

This preview shows document pages 1 - 2. Sign up to view the full document.

View Full Document Right Arrow Icon
Ask a homework question - tutors are online