私は C++ とスタック交換の初心者です。キーボード入力を取得し、比較する文字列と比較文字列と等しいかどうかに応じて出力する文字列を含む構造体の配列をループして正しいかどうかを確認するインターフェイス クラスに取り組んでいます。入力が正しければ、構造内の文字列が出力され、構造内の関数が呼び出されて何らかのアクションが実行されます。
インターフェイス.hpp
#include <string>
class Input_Interface {
struct command_output {
std::string command;
std::string success_string;
std::string failure_string;
void output_function();
}
bool stop_loop = false;
void Clear();
void Quit_loop();
};
インターフェイス.cpp
#include <iostream>
void Input_Interface::Quit_loop() {
stop_loop = true;
// ends loop and closes program
}
void Input_Interface::clear() {
// does some action
}
Input_Interface::command_output clear_output{"CLEAR", "CLEARED", "", Input_Interface::Clear()};
Input_Interface::command_output quit_output{"QUIT", "GOODBYE", "", Input_Interface::Quit_loop()};
Input_Interface::command_output output_arr[]{clear_output, quit_output};
void Input_Interface::begin() {
while (stop_loop == false) {
Input_Interface::get_input(); //stores input into var called input_str shown later
this->compare_input();
}
}
void Input_Interface::compare_input() {
for (unsigned int i=0; i<2; i++) {
if (this->input_str == output_arr[i].command) {
std::cout << output_arr[i].success_string << std::endl;
output_arr[i].output_function();
break;
}
}
// ... goes through else for failure printing invalid if it did not match any of the command string in the command_output struct array
私の問題はこれらの行にあります
Input_Interface::command_output clear_output{"CLEAR", "CLEARED", "", Input_Interface::Clear()};
//error: call to non-static function without an object argument
Input_Interface::command_output quit_output{"QUIT", "GOODBYE", "", Input_Interface::Quit_loop()};
//error: call to non-static function without an object argument
これがクラスのメンバー関数を介して渡されることは知っていますが、この問題を修正する方法がわかりません。問題が構造体オブジェクト内のスコープ解決演算子であるかどうかはよくわかりません。パラメーターの外で問題なく使用できるからです。
どんな助けでも大歓迎です。