-2

I am new to C++ and trying to understand a code related to OpenCV. It has a class as follow:

class Settings
{
public:
    Settings() : goodInput(false) {}
    enum Pattern { NOT_EXISTING, CHESSBOARD, CIRCLES_GRID, ASYMMETRIC_CIRCLES_GRID };
    enum InputType { INVALID, CAMERA, VIDEO_FILE, IMAGE_LIST };
.
.
.
.
}

what does Settings() : goodInput(false) {} means here. I don't think it is a constructor. Explain this please.

Ameer Hamza
  • 117
  • 2
  • 8

2 Answers2

2

It is indeed a constructor. What you see after : is called initializer-list and it initializes values before entering the curly brackets.

You should also know that member variables of a class are always initialized before entering the constructor body. If you don't mention a member variable in the initializer list, it will be default initialized.

Paolo M
  • 12,403
  • 6
  • 52
  • 73
0

It assigns the (default) initial value false to the member (probably) checking the validity of the input.

Ziezi
  • 6,375
  • 3
  • 39
  • 49