ItemArray constructor: Syntax

What is happening in the constructor?

1
2
3
4
5
6
7
8
struct ItemArray {
  RS_size count;
  RS_size capacity;
  t *items;

  ItemArray() { count(0), capacity(0), items(0) }; <-- ????
  //....//
}

> What is happening in the constructor?
> ItemArray() { count(0), capacity(0), items(0) }; <-- ????

A bunch of compile time errors. ( 'count' is not a function etc.)

Any of these would be ok.
ItemArray() { count = 0 ; capacity = 0 ; items = 0 ; }
or ItemArray() : count(0), capacity(0), items(0) {}
or ItemArray() : count{0}, capacity{0}, items{0} {}

Or simply:
1
2
3
4
5
struct ItemArray {
  RS_size count = 0 ;
  RS_size capacity = 0 ;
  t *items = 0 ;
};

or
1
2
3
4
5
struct ItemArray {
  RS_size count {0} ;
  RS_size capacity {0} ;
  t *items {0} ;
};


http://www.stroustrup.com/C++11FAQ.html#uniform-init
http://www.stroustrup.com/C++11FAQ.html#member-init
Topic archived. No new replies allowed.