Timeline for Arduino Libraries: Declaring variables as public?
Current License: CC BY-SA 4.0
9 events
| when toggle format | what | by | license | comment | |
|---|---|---|---|---|---|
| May 5, 2018 at 22:37 | comment | added | Pharap |
I'd like to challenge the premise of this question. Some Arduino classes do expose their member variables as public. For example EERef exposes index, as does EEPtr. Additonally, some classes declare their member variables as protectedso that inheriting clases can make use of them. The main reason though is usually because functions allow side effects to happen.
|
|
| May 5, 2018 at 21:13 | vote | accept | Henry | ||
| May 5, 2018 at 21:13 | vote | accept | Henry | ||
| May 5, 2018 at 21:13 | |||||
| May 5, 2018 at 21:13 | vote | accept | Henry | ||
| May 5, 2018 at 21:13 | |||||
| May 5, 2018 at 19:03 | comment | added | Gerben |
Sometimes setting a variable isn't enough, as the library might have to do some additional thing with that new value. E.g. when setting the size of a buffer object, that object would also need to allocate memory for this (new) size. As far as I can see C++ doesn't have true getters and setters like other programming languages. getters and setters would make it seem like you are setting a variable, but will actually call a function.
|
|
| May 5, 2018 at 18:48 | answer | added | ratchet freak | timeline score: 3 | |
| May 5, 2018 at 18:48 | answer | added | chrisl | timeline score: 2 | |
| May 5, 2018 at 18:33 | review | First posts | |||
| May 5, 2018 at 18:35 | |||||
| May 5, 2018 at 18:28 | history | asked | Henry | CC BY-SA 4.0 |