Member initializers

I'm working from the book "C++ How to Program" . I couldn't get the member initializers and I couldn't find it on the documentation here . Can someone explain it
i think i have this book in what chapter is it ?
I have the book and all the source code but I'm not sure what you actually want?
Section 10.2 figure 10.4 and 10.5 . I can't understand the parantheses count(c) increment(i) . I don't know about initialization
it seems that i have the old edition can you just wright part of the code that u didnt understand
so that we can understand the problem!!
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
 1  // Fig. 10.4: Increment.h
 2  // Definition of class Increment.
 3  #ifndef INCREMENT_H
 4  #define INCREMENT_H
 5
 6  class Increment
 7  {
 8  public:
 9     Increment( int c = 0, int i = 1 ); // default constructor
10
11     // function addIncrement definition
12     void addIncrement()
13     {
14        count += increment;
15     } // end function addIncrement
16
17     void print() const; // prints count and increment
18  private:
19     int count;
20     const int increment; // const data member
21  }; // end class Increment
22
23  #endif


1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
 1  // Fig. 10.5: Increment.cpp
 2  // Member-function definitions for class Increment demonstrate using a
 3  // member initializer to initialize a constant of a built-in data type.
 4  #include <iostream>
 5  using std::cout;
 6  using std::endl;
 7
 8  #include "Increment.h" // include definition of class Increment
 9
10  // constructor
11  Increment::Increment( int c, int i )
12     : count( c ), // initializer for non-const member        
13       increment( i ) // required initializer for const member
14  {
15     // empty body
16  } // end constructor Increment
17
18  // print count and increment values
19  void Increment::print() const
20  {
21     cout << "count = " << count << ", increment = " << increment << endl;
22  } // end function print

Topic archived. No new replies allowed.