Warnings on set-methods in a class?

I'm a retired developer and now and have started Arduino programming and have some habits from OOP in my younger days.

I used NOT DIRECTLY to manipulate the properties of class but do it by use of get/set-methods.

When I do that here I get WARNINGS - look here:

warning: ISO C++ forbids declaration of 'setState' with no type [-fpermissive]

Here is my code for the setState-method:

LED_Controller::setState(int st) {
_state = st;
}

and here is the most of my header file:

class LED_Controller {
private:
byte _pin = 0;
int _state = 0;
unsigned long _lastChanged = 0;
unsigned long _timeToActivate = 0;

public:

LED_Controller(byte GPIO_pin, 
               int state, 
               unsigned long lastChng,
               unsigned long timeToActi);
unsigned int  getTimeToActivate();
unsigned int  getLastChanged();
              setLastChanged(unsigned int lc);
int           getState();
              setState(int st);           <<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<< Here is the method !
byte          getPin();
unsigned long toggleLED();

};

I have 2 questions to ask you PROs:

  1. What is "best practice" - to manipulate the properties DIRECTLY or by set/get-methods ?
  2. How do I get rid of these warnings ?

Use "void"

Always use setters/getters

Please remember to use code tags when posting code

You must always tell the compiler the type of the return value of your function. If it doesn't have a return value you must use the type 'void'.

              void setState(int st);           <<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<< Here is the method !

Arghhhh, ofcause the void should be there
AND
I'll de the formatting in the future

THX for the quick responce to en newbee fool !'

This topic was automatically closed 120 days after the last reply. New replies are no longer allowed.