How to access variables within a custom library?


I am writing a program and it has gotten so large and full of functions it has become a bit unwieldy. So I have started to transfer functions to a library (I should have done this a while ago when it wasn’t so complicated and intertwined but now it is too late).

I had a global variable called bool shutterState that I use to do several checks. I moved that variable into a library where it is set. I had the variable as a public var but I couldn’t figure out how to access it via my main program. So I made it a private variable and created a function to return the state. Now I get the error below which makes no sense to me.

IRIS_ESP32_Controller_Temp:599:24: error: cannot convert 'Shutter::state' from type 'bool (Shutter::)()' to type 'bool'

       if (shutter.state) {


IRIS_ESP32_Controller_Temp:602:20: error: cannot convert 'Shutter::state' from type 'bool (Shutter::)()' to type 'bool'

       if (!shutter.state) {


IRIS_ESP32_Controller_Temp:602:20: error: in argument to unary !

this is where is I use it in my main()

if (inByte == 'm') {
      if (shutter.state) {
      if (!shutter.state) {
      Serial.println(" Shutter...");

this is my shutter.h file

#ifndef Shutter_h
#define Shutter_h

#include "Arduino.h"
#include <EEPROM.h>

class Shutter
		Shutter(int posPin, int negPin, int reg);
		void setup();
		void open();
		void close();
		void toggle();
		void setState(bool state);
		bool getState();
		bool state();

		int _posPin;
		int _negPin;
		int _reg;
		bool _state;


this is my shutter.cpp file

#include "Shutter.h"

Shutter::Shutter(int posPin, int negPin, int reg)
	pinMode(posPin, OUTPUT);
	_posPin = posPin;
	_negPin = negPin;
	_reg = reg;

void Shutter::setup()
	pinMode(_posPin, OUTPUT);
	pinMode(_negPin, OUTPUT);

void Shutter::open()
  digitalWrite(_posPin, HIGH);
  digitalWrite(_negPin, LOW);

void Shutter::close()
  digitalWrite(_posPin, LOW);
  digitalWrite(_negPin, HIGH);

void Shutter::toggle()
  _state = !_state;
  digitalWrite(_posPin, _state);
  digitalWrite(_negPin, !_state);

void Shutter::setState(bool _state)

    EEPROM.write(_reg, _state);
    if (_state == 1){
      stateText = "OPEN";
    if (_state == 0){
      stateText = "CLOSED";

bool Shutter::getState()
	_state = -1;
	_state =;
	Serial.print("getState = "); Serial.println(_state);
	if (_state == 0 || _state == 1){
		return true;
	} else {
		return false;

bool Shutter::state()
	return _state;

I don’t understand why it is saying I am trying to convert type ‘bool (Shutter::)()’ to type ‘bool’.

Any help would be greatly appreciated. Thanks.

if (shutter.state())

Oh jesus. Thanks. :o :o :o :o