次のタスクを実行するアプリケーションが 1 つあります。
1.) UI application will send command code (integer value).
2.) DLL interface(in c++) will get that integer value and execute corresponding command function.
コマンド名とコマンド コードは次のように維持されます。
#define PING 50
500 個のコマンドがあり、SWITCH CASE を適用するとうまく聞こえません。だから私は以下のように私のコードに関数ポインタを実装することにしました
#include "stdafx.h"
#include<iostream>
#define PING 20
using namespace std;
//extern const int PING = 10;
void ping()
{
cout<<"ping command executed";
}
void get_status(void)
{
cout<<"Get_status called"<<endl;
}
class ToDoCommands
{
public:
void getCommand( void (*CommandToCall)() );
};
void ToDoCommands::getCommand( void (*CommandToCall)())
{
void (*CommandToCall1)();
CommandToCall1 = CommandToCall;
CommandToCall1();
}
int main()
{
int code;
ToDoCommands obj;
cout<<"enter command code";
cin>>code; // if UI send 50 then Ping function get executed as #define PING 50
obj.getCommand(ping); // here m passing ping manually..
//obj.getCommand(get_status);
return 0;
}
コマンドコードに対応するコマンド名を渡すにはどうすればよいですか
obj.getCommand(ping);