Click here to Skip to main content
15,892,927 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
char *(*)(char *, char *)); 

hi, i need to allocate this pointer in c++, i am not sure how to do it, can any one explain this to me thanks.

What I have tried:

i did not understand anything about this pointer
Posted
Updated 22-Feb-18 6:59am

There is something missing in there.

char * defines the return type of the function pointer.

(*) is invalid as is; if you intend to declare a function pointer, you have to give it a name, for example (*function_name)
Besides, there is a closing bracket which does not match its opening one.

For example:
C
#include <iostream>
using namespace std;

char * func1(char *s1, char *s2) {
   return "In func1()\n";
}

char * func2(char *s1, char *s2) {
   return "In func2()\n";
}

int main() {
   char * (*myfunc)(char *, char *);
   myfunc = func1;
   cout << myfunc("", "");
   myfunc = func2;
   cout << myfunc("", "");
   return 0;
}

This produces the following output:
In func1()
In func2()


Hope this helps. Kindly.
 
Share this answer
 
v2
Comments
CPallini 22-Feb-18 12:58pm    
5.
 
Share this answer
 
v2
Comments
phil.o 22-Feb-18 13:54pm    
Interesting link. I bookmarked it, I'm quite sure it will appear handy somehow someday.
Thanks.

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900