* "Ook said:
Can some kind soul explain this line? I'm not quite sure what the different
parts do and exactly how it works.
public:
// Constructors
Zoot(int size = 0) : _size(size), _data(_size ? new int[_size] : 0) { }
Zoot
That's the name of the class.
(int size = 0)
One argument called 'size' that defaults to 0.
: _size(size),
The member '_size' is initialized with the value of 'size'.
_data(_size ? new int[_size] : 0)
The member '_data' is initialized with the value of
_size ? new int[_size] : 0
if '_size' is non-zero then 'new int[_size]' else 0.
{}
Does nothing in the constructor body.
General comments: this constructor only works if '_size' has been declared
before '_data'. Otherwise '_data' will be initialized first, using the
indeterminate value of '_size'. That is very ungood, and it's very simple to
avoid: use 'size' instead of '_size' in the '_data' initialization expression.
Since the problem is so easy to avoid and so totally unnecessary, this
constructor was either coded by a novice or as an illustration of this
problem.