-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.

user39086
  • 175
  • 3
  • 10

1 Answers1

1
  • Line 48 is a default constructor. This is the code that gets invoked when you declare a variable of type entry, and do not specify initialization parameters.
  • Line 49 is another constructor. This is the code that gets invoked when you declare a variable of type entry, and pass two unsigned int parameters.
  • Line 134 is a declaration of a reference of type entry. The ampersand says that ecur is not a copy of iter->second, but rather a reference to it. Any change to ecur would be reflected in iter->second, because they refer to the same variable.

You can read more about constructors here. Here is a tutorial on reference variables.

Sergey Kalinichenko
  • 714,442
  • 84
  • 1,110
  • 1,523