C / C++ / C#

  1. Home
  2. Computing & Technology
  3. C / C++ / C#

C++ Tutorial - Advanced Pointers

By David Bolton, About.com

8 of 8

Recapping function Pointer Syntax

C++ lets you write some of the most unreadable syntax possible, though we've only scratched the surface so far. When it comes to templates then it really gets interesting.

When you want to use function pointers (class or non class) here are the steps. Start with a function definition. Eg.int DoAnalysis(int a,string label);. Now rRemove parameter names ....int DoAnalysis(int,string); and add the (* ... ) to get

int (*DoAnalysis)(int,string)
This is your variable type. You'll store an instance of this. Change the function name to something to remind you
int (*pointerToTwoParamIntFunction)(int,string)
If you are pointng to a class method, add the class name prefix classname::Eg
int (Classname::*pointerToTwoParamIntFunction)(int,string)
Before calling it, check the value is assigned!
if (pointerToTwoParamIntFunction ==0)
  return;
pointerToTwoParamIntFunction(int i, string s)

That completes this tutorial. The next one will be on C++ strings.

Explore C / C++ / C#

About.com Special Features

Build Your Own Website

Step-by-step advice on how to do everything from choosing a Web host to promoting your content. More >

Connect Your Home Computers

Easy ways to connect two computers for networking purposes. More >

C / C++ / C#

  1. Home
  2. Computing & Technology
  3. C / C++ / C#
  4. C++
  5. Learn C++ Programming
  6. Recapping Function Pointer Syntax

©2009 About.com, a part of The New York Times Company.

All rights reserved.