Why wont return work?

I'm not sure whats happening but my peice of code broke at some point and now it can't detect pressing return. This is all in a function.

1
2
3
4
5
6
7
8
9
10
            while(not GetAsyncKeyState(VK_RETURN)){
                if(GetAsyncKeyState(VK_RETURN)){
                    cout << "True";
                    return true;
                }
                  if(GetAsyncKeyState(VK_UP)||GetAsyncKeyState(VK_DOWN)||GetAsyncKeyState(VK_LEFT)|| GetAsyncKeyState(VK_RIGHT)){
                     cout << "False";
                     return false;
                }
            }

Its probably obvious.
Last edited on
Firstly, the keywords 'not', 'and' and 'or' work slightly differently to '!', '&&' and '||' in some compilers.

Microsoft, I'm pointing at you!

Use the /Za flag to allow them to work (and disable MS-specific extensions).
For example: CL /EHsc /Za myprogram.cpp
http://msdn.microsoft.com/en-us/library/1k6w8551%28v=vs.110%29.aspx

Now, if that code is inside a bool function (i.e. a function that returns a bool), then I'm hoping there's another 'return' after that code (at the very least as a sanity test).

If it's outputting the text (either "True" or "False") but not returning then TBH you've found a compiler bug, that pretty much shouldn't happen at all! So it's probably not what's happened and you may not be detecting what it returns properly, where's the code that makes you think it's not returning properly?
Topic archived. No new replies allowed.