I got a task to create a map with key values and functions inside. I managed to do that. Now I need to create a loop where I need to call a different print function by pressing up, down, left, right keyboard buttons(eg, i press up, the function prints "UP"). Any idea how? My mentor told me that its a practice for understanding the usage of function object. Here is my program for now:
#include <functional>
#include <iostream>
#include <string.h>
#include <map>
using namespace std;
void up (){
cout<<"UP";
}
void down (){
cout<<"DOWN";
}
void left (){
cout<<"LEFT";
}
void right (){
cout<<"RIGHT";
}
int main (){
typedef map<int, void (*)()> mapaF;
mapaF Kretnje;
Kretnje.insert(pair<int,void (*)() >(1, up));
Kretnje.insert(pair<int, void (*)()>(2, down));
Kretnje.insert(pair<int, void (*)()>(3, left));
Kretnje.insert(pair<int, void (*)()>(4, right));
for(auto a: Kretnje){
cout<<"Kljuc: "<<a.first<<" Funkcija: ";
a.second();
cout<<endl;
}
return 0;
}