fork download
  1. #include <cstdlib>
  2. #include <iostream>
  3. using namespace std;
  4.  
  5. void add() { cout<<"dodajemy"<<endl; }
  6. void mul() { cout<<"mnożymy"<<endl; }
  7. void stop() { exit(0); }
  8.  
  9. typedef void fun();
  10. struct { const string cmd; fun *call; } tb[]=
  11. {
  12. {"+",&add},
  13. {"*",&mul},
  14. {"stop",[]() -> { exit(0); }},
  15. };
  16.  
  17. int main()
  18. {
  19. for(string cmd;getline(cin,cmd);)
  20. {
  21. bool found=false;
  22. for(const auto &r:tb)
  23. {
  24. if(r.cmd==cmd)
  25. {
  26. r.call();
  27. found=true;
  28. break;
  29. }
  30. }
  31. if(!found) cout<<"Nieznane polecenie"<<endl;
  32. }
  33. }
Compilation error #stdin compilation error #stdout 0s 4548KB
stdin
2+3
4*7
3*9
5^8
1+2
stop
compilation info
prog.cpp:14:18: error: expected type-specifier before ‘{’ token
  {"stop",[]() -> { exit(0); }},
                  ^
prog.cpp:15:1: error: invalid user-defined conversion from ‘<lambda()>’ to ‘void (*)()’ [-fpermissive]
 };
 ^
prog.cpp:14:18: note: candidate is: ‘<lambda()>::operator int (*)()() const’ <near match>
  {"stop",[]() -> { exit(0); }},
                  ^
prog.cpp:14:18: note:   no known conversion from ‘int (*)()’ to ‘void (*)()’
stdout
Standard output is empty