minDist(100) 和这段代码中的大括号是什么意思

What does minDist(100) and the curly braces in this piece of code mean?

本文关键字:是什么 意思 段代码 minDist 代码      更新时间:2023-10-16

我刚刚遇到了一段让我感到困惑的代码。它是一个头文件,用于定义一个名为 ColorDetector 的类。私人部分如下:

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]);
  }

这是这个类的公开声明,让我感到困惑:

public:
  // empty constructor
  ColorDetector() : minDist(100) {
      // default parameter initialization here
      target[0]= target[1]= target[2]= 0;
  }

我不太清楚这个构造函数中的语法。mindset(100) 在这里是什么意思,为什么目标数组写在大括号内?我用关键字"默认构造函数"和"默认参数"搜索谷歌,但没有找到相关的文章。有人可以告诉我这段代码的确切含义吗?

这个类

这是成员初始化列表,请参阅 http://en.cppreference.com/w/cpp/language/initializer_list