I
I
Igor2019-05-11 19:50:14
Arduino
Igor, 2019-05-11 19:50:14

What does the ":" operator do in this case in c++?

Good afternoon! I recently came across this code for creating a button class for Arduino:

The code
//...
class Button
{
  public: Button (uint8_t pin, bool pullup = false, uint16_t debounceDelay = 50)
    : _pin(pin), _state(LOW), _lastState(LOW),
      _lastMillis(0), _debounceDelay(debounceDelay),
      _lastDebounceTime(0)
  {
    if (pullup == true)
    {
      pinMode(_pin, INPUT_PULLUP);
    }
    else
    {
      pinMode(_pin, INPUT);
    }
}
//...

I was surprised how the operator :(line 5) is used here, and in general the whole construction after it. If anyone knows, please tell me what it is, or better just give a link to a reference resource, I will be very grateful.
Thanks in advance!

Answer the question

In order to leave comments, you need to log in

1 answer(s)
E
Evgeny Shatunov, 2019-05-11
@Igorello74

This is called the initialization section . In this section, you can independently initialize the fields of the created object even before passing control to the constructor body.
Starting with C++11, you can specify constructor delegation in the initialization section. The selected constructor will also be executed before entering the body of the current constructor.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question