struct with member function as parameter

后端 未结 1 1124
离开以前
离开以前 2021-01-07 11:23

I am a beginner in C++ and stack exchange. I am working on an Interface class that gets keyboard input and checks to see whether it is correct through looping through an arr

1条回答
  •  执笔经年
    2021-01-07 12:19

    You should do something as shown below:

    #include 
    struct Input_Interface {
        struct command_output {
          std::string command;
          void (*output_function)();
        };
    
        static void Clear();
        static void Quit_loop();
    };
    
    int main() {
        Input_Interface::command_output t = {"CLEAR", Input_Interface::Clear};
        return 0;
    }
    

    Live example here

    Although I would suggest using a functor object over function pointer.

    0 讨论(0)
提交回复
热议问题