Calling a function from function name
CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 4 of 4

Thread: Calling a function from function name

  1. #1
    Join Date
    Jun 2009
    Posts
    8

    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

  2. #2
    Join Date
    Jan 2004
    Location
    Düsseldorf, Germany
    Posts
    2,401

    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.

  3. #3
    Join Date
    Nov 2006
    Location
    Essen, Germany
    Posts
    1,344

    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).

  4. #4
    Join Date
    Jun 2009
    Posts
    8

    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
  •  


Windows Mobile Development Center


Click Here to Expand Forum to Full Width

This is a CodeGuru survey question.


Featured


HTML5 Development Center