fork(1) download
  1. #include <functional>
  2. #include<map>
  3. #include<string>
  4.  
  5. class Calc {
  6.  
  7. private:
  8.  
  9. void Naming() {}
  10. std::map<std::string, std::function <void(Calc*)>> Command_Name;
  11.  
  12. public:
  13.  
  14. Calc() {
  15. Command_Name["var"] = &Calc::Naming;
  16. }
  17.  
  18. void operator()() {
  19. Command_Name["var"]();
  20. }
  21. };
  22.  
  23. int main() {
  24. Calc calculater;
  25. calculater();
  26. return 0;
  27. }
Compilation error #stdin compilation error #stdout 0s 0KB
stdin
Standard input is empty
compilation info
prog.cpp: In member function ‘void Calc::operator()()’:
prog.cpp:19:29: error: no match for call to ‘(std::map<std::__cxx11::basic_string<char>, std::function<void(Calc*)> >::mapped_type {aka std::function<void(Calc*)>}) ()’
         Command_Name["var"]();
                             ^
In file included from /usr/include/c++/8/functional:59,
                 from prog.cpp:1:
/usr/include/c++/8/bits/std_function.h:682:5: note: candidate: ‘_Res std::function<_Res(_ArgTypes ...)>::operator()(_ArgTypes ...) const [with _Res = void; _ArgTypes = {Calc*}]’
     function<_Res(_ArgTypes...)>::
     ^~~~~~~~~~~~~~~~~~~~~~~~~~~~
/usr/include/c++/8/bits/std_function.h:682:5: note:   candidate expects 1 argument, 0 provided
stdout
Standard output is empty