Compiler issue with particle.variable

I have an instance of an object Gate, called the_Gate. The code below is exposing a variable that is private inside the object, the accessor function for that variable is getGateOpenSwitchState. The code below compiles fine. The next set does not. Any ideas?

int foo = the_Gate.getGateOpenSwitchState();
Particle.variable("readOpen", &(foo), INT);

Particle.variable("readOpen", &(the_Gate.getGateOpenSwitchState()), INT);

The compiler returns ‘value required as unary & operand’

    void gate_running_timeout();
    gate_state current_GateState;
    Timer gate_timer;
    int openSwitch = OPENSWITCH;
    int closedSwitch = CLOSESWITCH;
    int openSwitchValue;
    int closedSwitchValue;


int Gate::getGateOpenSwitchState(){
	openSwitchValue = gpio.digitalRead(openSwitch);



Particle.variable() needs to obtain the phyiscal address of a global/static variable, not the address of a temporary return value.

BTW, you are using the deprecated 3-parameter syntax of Particle.variable()

1 Like

Thanks, make sense.