-
June 15th, 2009, 07:30 AM
#1
Calling a function from function name
Hello,
In c++, let us consider that we have a string or char* functionName and that we know the signature (output and input arguments types) of the function we want to call.
Is there a way to call this function ? I think I have to use function pointer.. But still the problem is to find the pointer of the function by using its name.
Thanks in advance,
rilpo
-
June 15th, 2009, 07:40 AM
#2
Re: Calling a function from function name
In short: No. C++ does not have anything corresponding to Java reflection. You need to know the address where the function is stored to call it, not it's name.
More computing sins are committed in the name of efficiency (without necessarily achieving it) than for any other single reason - including blind stupidity. --W.A.Wulf
Premature optimization is the root of all evil --Donald E. Knuth
Please read Information on posting before posting, especially the info on using [code] tags.
-
June 15th, 2009, 07:49 AM
#3
Re: Calling a function from function name
That´s not possible in C/C++. Using a std::map storing string/fn pointers pairs might be a solution, but you have to fill the map on your own. You also need a separate map for each function type (signature).
- Guido
-
June 16th, 2009, 02:38 AM
#4
Re: Calling a function from function name
Ok thank you for this answer, also for the concept of reflection. So I will use a map.
Tags for this Thread
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|