I'm having some trouble with a macro in C++. I am using C code as a reference so of course what I am trying to do may not be possible in C++. I'm using VS2010 to compile.
The example C code I am using as a reference has the macro:
#define IS_PRESSED(dev, button) ((dev->btns & button) == button)
This macro is used in an if statement in the format:
if (IS_PRESSED(wm, WIIMOTE_BUTTON_A))
{}
Where WIIMOTE_BUTTON_A is a hex value. As you can see, this code allows any button to be checked, losing the need to have a function for each button.
I want to recreate this code in C++. Here's what I have so far:
#define BUTTON_PRESSED(wm,btn) (wm->remote.Button.btn() && !wm->lastButtonState.last_btn)
and called in the if statement:
if(BUTTON_PRESSED(wiimote,'A'))
The compiler doesn't like the call to 'BUTTON_PRESSED', saying it 'expected a member name'. I'm not sure if passing a char will work either, but that's not the main problem.
Everywhere I look I find pages telling me not to use macro functions in C++, but I can't find anywhere which will tell me what to use instead! Am I going to have to write out nearly identical functions for each button I want to check?
Thanks in advance, Simon.

New Topic/Question
Reply



MultiQuote




|