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?

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

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

The compiler returns ‘value required as unary & operand’

.......
.....
    private:
    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);
	return(openSwitchValue);
}

.....
.....

matt

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.