Replies: 1 comment 1 reply
-
Ok first sorry for the stupid question above.. I have found how to do it. The trick is basically capturing not the references but the values i.e. replacing the & by = in the lamba expression in the for loop. That way it works. Is it the right way to do this sort of things though ? No idea //grbba |
Beta Was this translation helpful? Give feedback.
1 reply
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
-
Hello,
i must have a fundamental misunderstanding of C++ lambdas i guess but nevermind. I have a vector of structs which hold
the name, vector of the parameter descriptions and a help string over which I iterate to insert them into the menu.
In the lambda there is one call to execute the command which shall take the name of the menu item and in the execution function display them. ( As i will have quite some variable parameter number commands and not wanting to have n times the same command in the list for each possible parameter number as well as having too much copy paste programming to do for the Insert Commands ). I'd like to capture the name of the command in the executor so i know what to do next.
That works fine for defining the commands in the menu. They show up as expected but the name printed in the executeMenu() above is always the name of the last command entered through the loop ... and when executed several times nothing shows up again as you can see below
I guess i have just something very simple to do to get this going but i can't get my head around this with my little programming experience
The struct which contains everything i need is build from JSON strings so that i can add easily new menu items by just editing their description and providing the function to execute what they should do. All the wiring is taken care of ...
Doing it this way where m1 m1desc and m1help are individually instantiated global variables works fine:
Full file from which i tested:
main.cpp.txt
Thanks a lot for your help
//
Beta Was this translation helpful? Give feedback.
All reactions