0
C++でCommands(ファイル名commands.cpp)というクラスを作成しました。クラスの配列の関数を呼び出す方法C++
私はそれを取って、コマンド列(ファイル名TEST.CPP)に入れてきました。私が知りたいのですがどのような
は、コマンドクラス内にある関数を呼び出す方法です。例えば
私は
void command::init(char data[])
{
//detail
}
と呼ばれるコマンドクラス 内の機能を持っており、私は関数を呼び出すために行うことを試みたことは
EDIT
Class test{
int CmdCount; // number of commands in the array
int MaxCmds; // max amount of commands allowed
command* cmds;
Public:
int get_command_count() const{
return CmdCount;
}
int readfile(const char fname[]){
char line[161];
FILE* fp;
fp = fopen(fname, "r");
if(fp){
for(int i = 0; 1 == fscanf(fp, "%160[^\n]\n", line; i++){
cmds[get_command_count()].init(line);
CmdCount += 1;
}
}
fclose(fp);
}
};
です
void command :: inを呼び出す方法を知りたいit(char data [])。
提案がありますか?
ありがとうございました。
あなたは何が問題ですか?つまり、 'cmds [get_command_count()] .init(line);' –
は 'init'です。' line'が 'char *'と 'cmds'であれば、クラスのpublicメソッドです。 'get_command_count()'は有効な配列インデックスを返す – keety
'get_command_count'は有効なコマンドの総数*を与えるかのように聞こえます。この場合、有効なコマンドではない最初のインデックスです。 – celtschk