0

I've just met a piece of code that made me confused. It's a header file that defines a class named ColorDetector. The private part is as follows:

class ColorDetector {
  private:
  // minimum acceptable distance
  int minDist;

  // target color
  cv::Vec3b target;

  // image containing resulting binary map
  cv::Mat result;

  // inline private member function
  // Computes the distance from target color.
  int getDistance(const cv::Vec3b& color) const {
     // return static_cast<int>(cv::norm<int,3>(cv::Vec3i(color[0]-target[0],color[1]-target[1],color[2]-target[2])));
      return abs(color[0]-target[0])+
                abs(color[1]-target[1])+
                abs(color[2]-target[2]);
  }

Here's the public declaration of this class that made me confused:

public:

  // empty constructor
  ColorDetector() : minDist(100) {

      // default parameter initialization here
      target[0]= target[1]= target[2]= 0;
  }

I am not quite clear about the grammar in this constructor here. What does mindset(100) mean here and why the target array is written within curly braces? I searched google with keyword "default constructor" and "default parameter" but found no relating articles. Can someone tell me the exact meaning of this piece of code here?

The class of this

Paul R
  • 208,748
  • 37
  • 389
  • 560
Lake_Lagunita
  • 521
  • 1
  • 4
  • 20
  • 2
    It's just a fairly straightforward constructor - this should be covered in chapter 1 of pretty much any decent C++ book. You are using a [decent C++](http://stackoverflow.com/questions/388242/the-definitive-c-book-guide-and-list) book to learn the language, I hope ? – Paul R Jun 15 '15 at 07:56
  • 1
    Possible duplicate of [What is this weird colon-member (" : ") syntax in the constructor?](http://stackoverflow.com/questions/1711990/what-is-this-weird-colon-member-syntax-in-the-constructor) – Frédéric Hamidi Jun 15 '15 at 08:02
  • great. Thanks a lot! :) – Lake_Lagunita Jun 15 '15 at 08:32

1 Answers1

0

This is member initialization list see http://en.cppreference.com/w/cpp/language/initializer_list

coincoin
  • 4,595
  • 3
  • 23
  • 47