は、おそらくあなたは反射のいずれかの種類をサポートしていません
#include <string>
#include <map>
class CmdHandler // our handler class
{
public:
void Handler(const std::string &arg){}//our handler method
};
typedef void (CmdHandler::*MethodPtr)(const std::string &); // make typedef to easily deal with the type of the member-function pointer
std::map<std::string, MethodPtr> my_handlers; // make our method lookup table
int _tmain(int argc, _TCHAR* argv[])
{
CmdHandler handler;
//add a real member-function pointer for the "say" command
my_handlers.insert(std::make_pair("say", &CmdHandler::Handler));
//look for the handler of command "say" and call it instantly
(handler.*my_handlers["say"])("something");
return 0;
}
感謝。あなたのコードで何が起こっているのかを説明できますか? –
コードにコメントします。ちょっと待って... – Jurlie
はこれで今はっきりしていますか? – Jurlie