//---------------------------------------------------------------------------
#include <iostream>
#include <string>
#include <map>
#pragma hdrstop
typedef void (*FUNC_PTR)(void);
typedef std::map<std::string,FUNC_PTR> FUNC_MAP;
void foo(void)
{
std::cout << "call function 'foo'" << std::endl;
}
//---------------------------------------------------------------------------
void bar(void)
{
std::cout << "call function 'bar'" << std::endl;
}
//---------------------------------------------------------------------------
#pragma argsused
int main(int argc, char* argv[])
{
FUNC_MAP func_map;
func_map["foo"]=&foo;
func_map["bar"]=&bar;
std::string input;
std::cout << "input function name: ";
std::cin >> input;
FUNC_MAP::iterator iterator=func_map.find(input);
if(iterator!=func_map.end())
{
(iterator->second)();
} else
{
std::cout << "can't find function '" << input << "'" << std::endl;
}
return 0;
}
//---------------------------------------------------------------------------
|