Click here to Skip to main content
15,895,667 members
Home / Discussions / C / C++ / MFC
   

C / C++ / MFC

 
GeneralRe: Calling a function using as your name the content a CString Pin
Samuel Nunes de Arruda27-Sep-11 10:09
Samuel Nunes de Arruda27-Sep-11 10:09 
AnswerRe: Calling a function using as your name the content a CString Pin
Maximilien27-Sep-11 9:13
Maximilien27-Sep-11 9:13 
GeneralRe: Calling a function using as your name the content a CString Pin
Samuel Nunes de Arruda27-Sep-11 9:58
Samuel Nunes de Arruda27-Sep-11 9:58 
AnswerRe: Calling a function using as your name the content a CString Pin
Chris Meech27-Sep-11 9:22
Chris Meech27-Sep-11 9:22 
GeneralRe: Calling a function using as your name the content a CString Pin
Chuck O'Toole27-Sep-11 10:13
Chuck O'Toole27-Sep-11 10:13 
GeneralRe: Calling a function using as your name the content a CString Pin
Samuel Nunes de Arruda27-Sep-11 10:16
Samuel Nunes de Arruda27-Sep-11 10:16 
GeneralRe: Calling a function using as your name the content a CString Pin
Richard MacCutchan27-Sep-11 22:14
mveRichard MacCutchan27-Sep-11 22:14 
AnswerRe: Calling a function using as your name the content a CString Pin
TheGreatAndPowerfulOz28-Sep-11 9:05
TheGreatAndPowerfulOz28-Sep-11 9:05 
You can use an map of function pointers to accomplish this.

This is assuming all the functions have the same signature, that is same return type and same numbers and types of parameters.

typedef void (*VoidFuncType)();

map<string, VoidFuncType> functions;

functions["myFunction1"] = myFunction1;
functions["myFunction2"] = myFunction2;

...

string func = "myFunction1";

...

functions[func]();


Note that myFunction1 and myFunction2 are functions or methods in your code.

If they are member functions, then the typedef will need to be different, and so will the subsequent usage.

Be sure to
#include <map>

If your actions inspire others to dream more, learn more, do more and become more, you are a leader." - John Quincy Adams
You must accept one of two basic premises: Either we are alone in the universe, or we are not alone in the universe. And either way, the implications are staggering” - Wernher von Braun


modified 28-Sep-11 17:11pm.

GeneralRe: Calling a function using as your name the content a CString Pin
Samuel Nunes de Arruda28-Sep-11 10:40
Samuel Nunes de Arruda28-Sep-11 10:40 
GeneralRe: Calling a function using as your name the content a CString Pin
TheGreatAndPowerfulOz28-Sep-11 11:04
TheGreatAndPowerfulOz28-Sep-11 11:04 
QuestionShow text after press a button Pin
antonio34327-Sep-11 8:29
antonio34327-Sep-11 8:29 
AnswerRe: Show text after press a button Pin
Albert Holguin27-Sep-11 9:20
professionalAlbert Holguin27-Sep-11 9:20 
GeneralRe: Show text after press a button Pin
antonio34327-Sep-11 12:04
antonio34327-Sep-11 12:04 
GeneralRe: Show text after press a button Pin
Albert Holguin28-Sep-11 3:57
professionalAlbert Holguin28-Sep-11 3:57 
GeneralRe: Show text after press a button Pin
antonio34328-Sep-11 6:13
antonio34328-Sep-11 6:13 
GeneralRe: Show text after press a button Pin
Albert Holguin28-Sep-11 7:10
professionalAlbert Holguin28-Sep-11 7:10 
Questionapriori algorithm Pin
salv0327-Sep-11 7:24
salv0327-Sep-11 7:24 
AnswerRe: apriori algorithm [modified] Pin
Chris Meech27-Sep-11 8:16
Chris Meech27-Sep-11 8:16 
GeneralRe: apriori algorithm [modified] Pin
salv0327-Sep-11 8:28
salv0327-Sep-11 8:28 
AnswerRe: apriori c++ algorithm Pin
Software_Developer27-Sep-11 19:59
Software_Developer27-Sep-11 19:59 
GeneralRe: apriori c++ algorithm Pin
salv0328-Sep-11 6:29
salv0328-Sep-11 6:29 
GeneralRe: apriori c++ algorithm Pin
David Crow28-Sep-11 7:10
David Crow28-Sep-11 7:10 
QuestionMessage Removed Pin
27-Sep-11 3:24
Youming Lee27-Sep-11 3:24 
AnswerRe: allocate memory Pin
Code-o-mat27-Sep-11 3:32
Code-o-mat27-Sep-11 3:32 
GeneralRe: allocate memory Pin
Youming Lee27-Sep-11 4:12
Youming Lee27-Sep-11 4:12 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.