Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people, just like you, are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
Solved

Array of function pointers

Posted on 1998-05-18
4
210 Views
Last Modified: 2013-12-26
Is it possible to create an array of function pointers and if so how ?
0
Comment
Question by:ShriramS
  • 2
  • 2
4 Comments
 
LVL 3

Accepted Solution

by:
msmits earned 20 total points
ID: 1299676
It should not be necessary in C++ and object-oriented programming to use arrats of function pointer, but technically it is possible.

void (*pfa[10])(char*);

Which is an array of 10 pointers to functions that return void and take a char* as parameter.

void xyz(char *x)
{
}

pfa[0] = xyz;

0
 
LVL 1

Author Comment

by:ShriramS
ID: 1299677
What I need to do is have a array of pointers in a class without knowing how many items I need in the array. How do I deal with that ? Can I declare a pointer in the declaration and then define it as an array in the constructor for example ?
0
 
LVL 3

Expert Comment

by:msmits
ID: 1299678
That depends on when you know how may pointer you need. If you know it at constructor time, you can create a pointer to an array of pointers and allocate the memory at constructor time for just the number of elements you need.

void (**pfa)(char*);

void xyz(char *x)
{}

X:x(int n) {
  pfa = new (void (*[n])(char *));
  pfa[0] = xyz;
}

pfa[0]("hello");

If you want real dynamic array, you need to use the vector class from the Standard Library.

0
 
LVL 1

Author Comment

by:ShriramS
ID: 1299679
Thank You
0

Featured Post

Free Tool: Site Down Detector

Helpful to verify reports of your own downtime, or to double check a downed website you are trying to access.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Title # Comments Views Activity
RSS Feeds--IE 13 185
PHP email variable syntax 3 53
character entities and entity references in XML 17 134
CSS Question.. 3 92
Article by: Matthew
I am a very big proponent of technology compliance standards and strive to meet such criteria in all of my work. That includes my site, which is 100% XHTML 1.0 compliant as determined by the World Wide Web Consortium. https://www.matthewstevenkel…
SASS allows you to treat your CSS code in a more OOP way. Let's have a look on how you can structure your code in order for it to be easily maintained and reused.
Viewers will learn about if statements in Java and their use The if statement: The condition required to create an if statement: Variations of if statements: An example using if statements:
The viewer will learn how to create and use a small PHP class to apply a watermark to an image. This video shows the viewer the setup for the PHP watermark as well as important coding language. Continue to Part 2 to learn the core code used in creat…

861 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question