Calling function based on passing variable.......

This is a discussion on Calling function based on passing variable....... within the C++ Programming forums, part of the General Programming Boards category; can we calling defined function based on passing variable in C++ like on PHP? for example, in PHP we can ...

  1. #1
    Registered User
    Join Date
    Dec 2011
    Posts
    7

    Calling function based on passing variable.......

    can we calling defined function based on passing variable in C++ like on PHP?

    for example, in PHP we can calling function like:

    Load_$Input();


    CMIIW.

  2. #2
    C++ Witch laserlight's Avatar
    Join Date
    Oct 2003
    Location
    Singapore
    Posts
    23,629
    No, C++ does not support variable functions. However, as long as you can map strings to function pointers (or function objects), you can do something similiar.
    Quote Originally Posted by Bjarne Stroustrup (2000-10-14)
    I get maybe two dozen requests for help with some sort of programming or design problem every day. Most have more sense than to send me hundreds of lines of code. If they do, I ask them to find the smallest example that exhibits the problem and send me that. Mostly, they then find the error themselves. "Finding the smallest program that demonstrates the error" is a powerful debugging tool.
    Look up a C++ Reference and learn How To Ask Questions The Smart Way

  3. #3
    Registered User
    Join Date
    Dec 2011
    Posts
    7
    is there any tutorial about that? sorry i'm newbie in C++.

  4. #4
    C++ Witch laserlight's Avatar
    Join Date
    Oct 2003
    Location
    Singapore
    Posts
    23,629
    Tutorial on std::map and std::unordered_map, or tutorial on function pointers and function objects?
    Quote Originally Posted by Bjarne Stroustrup (2000-10-14)
    I get maybe two dozen requests for help with some sort of programming or design problem every day. Most have more sense than to send me hundreds of lines of code. If they do, I ask them to find the smallest example that exhibits the problem and send me that. Mostly, they then find the error themselves. "Finding the smallest program that demonstrates the error" is a powerful debugging tool.
    Look up a C++ Reference and learn How To Ask Questions The Smart Way

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Replies: 3
    Last Post: 09-26-2011, 04:44 AM
  2. Calling a function named in a variable.
    By JohnAnon in forum C++ Programming
    Replies: 25
    Last Post: 04-01-2011, 12:38 AM
  3. Replies: 6
    Last Post: 06-01-2007, 07:02 PM
  4. Replies: 5
    Last Post: 01-12-2006, 11:00 PM
  5. Passing a function name as a variable to execute it?
    By Zuul in forum C++ Programming
    Replies: 2
    Last Post: 01-03-2002, 11:42 AM

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21