-3

I just started learning "class" and other advanced techniques in C++ in order to understand the following C++ snippet. Please don't down rate the question if you think it's silly because I've searched online before asking!

The code implements an online quantile algorithm called 'GK method'. I try to understand the practical work flow of the algorithm by learning the code. The full code has 191 lines so I didn't copy it here, it is located at: https://github.com/coolwanglu/quantile-alg/blob/master/gk.h

The part of the code I don't understand is list below:

46     class entry{ 
47     public: 
48         entry () { } 
49         entry (unsigned int _g, unsigned int _d) : g(_g), delta(_d) { } 
50         unsigned int g,delta; 
51     }; 

I don't understand what #48,49 means.

134         entry & ecur = iter->second; 

Here what does "Type & Name" mean?

Finally, if anyone who's familar with GK method happen to see this: Could you explain to me, or suggest any references that explain the practical implementation of this method. Thanks.

4

1 回答 1

1
  • 第 48 行是默认构造函数。这是在声明类型变量时调用的代码entry,并且不指定初始化参数。
  • 第 49 行是另一个构造函数。这是在声明类型变量entry并传递两个unsigned int参数时调用的代码。
  • 第 134 行是类型引用entry的声明。& 号表示这ecur不是 的副本iter->second,而是对它的引用。任何更改ecur都将反映在 中iter->second,因为它们引用相同的变量。

您可以在此处阅读有关构造函数的更多信息。这是关于参考变量的教程

于 2014-09-20T01:12:50.353 回答