Блог пользователя khanhdungtrinh

Автор khanhdungtrinh, история, 10 месяцев назад, По-английски

This code is from: https://codeforces.net/blog/entry/86731 ~~~~~ struct Line { data_t a, b;

Line() : a(0), b(-inf) {} Line(data_t a, data_t b) : a(a), b(b) {}

data_t get(data_t x) { return a * x + b; } }; ~~~~~

I have no idea what the colon marks in the code means?

  • Проголосовать: нравится
  • +2
  • Проголосовать: не нравится

»
10 месяцев назад, # |
  Проголосовать: нравится +10 Проголосовать: не нравится

It is used in constructors to initialize member variables of classes/structs. The variables outside the parentheses are member variables and the values within the corresponding parentheses are the values to which you initialize the member variables.

This is generally the preferred method of initializing values in classes/structs when possible.

  • »
    »
    10 месяцев назад, # ^ |
    Rev. 2   Проголосовать: нравится +1 Проголосовать: не нравится

    One advantage of this synatax is that it allows one to initialise a const variable with some value. This can be helpful if we don't want to change size of a structure after it is initialised.

    Example
  • »
    »
    10 месяцев назад, # ^ |
      Проголосовать: нравится 0 Проголосовать: не нравится

    I got it, thanks.