Not really sure how to phrase this properly but what i have now is a case switch when a key is pressed, something happens, how would i be able to make it so after it has been pressed ones, that case gets disable?
eg of what i have now:
if(abc = 1){
key gets press = c
switch (c)
{
case f1 : cout << 1; break;
case f2 : cout << 2; break;
case f3 : cout << 3; break;
....
}
}
=============
So after pressing f1 for the first time, it would print "1" out and then you wont be able to press it again. but you can still press f2 and f3.
is there something like
if(abc = 1){
key gets press = c
switch (c)
{
case f1 : cout << 1;(DISABLE CASE F1); break;
case f2 : cout << 2; break;
case f3 : cout << 3; break;
....
}
}
im not going to lie, upon reading that i jumped to duffs device... god the nightmares. anyway, switches are very easy going and flexible. just do something like this:
you dont understand what hes asking at all. no one said anything about containers and i definitly didnt. the part i quoted is you describing what a switch does. if you would actually read the post, you would see that he wants something to happen when he presses c, and then if he presses it again, he doesnt want that thing to happen again. so my example shows how to do that.
actually yes i did. he wants the ability to press any key. then when f1 is pressed, he can still press any key but f1 wont do anything. you are wrong. he said nothing of needing a container
And he said nothing about needing another variable. not to mention that your code simply don't work.
Using a container is one of the means to achieve desired result: track used options. You could use a bunch of boolean variables, mutable function pointers and other ways. To say that one of them is better is wrong. For beginners a bunch of booleans will be more intuitive. I could use a map of char and function pointer to get rid of switch completely or bitset, depending on situation.
... i will try to explain this in a way you can understand... containers are used for holding lots of data. there are specialized versions yes, but their core function is to hold data. thats not what he asked to do. he said he wants to press the f1 key and something happens, and press it again but nothing will happen. he said nothing of trying to keep track of what was pressed, only to make sure that it could only be pressed once. of course you could get rid of the switch, but thats what he was using. your map idea only works if a) functions were going to be used, b) they have the same return type, and c) take the same number and type of args, and none of that is guaranteed from his code. of course my code doesnt work, it was pseudo code because if i write the code for him he doesnt work. if i used real values then it would work