That colon means that what follows is an initializer list. In constructor definitions, between the name and the body can sit an initializer list. This code:
Code:
Tree::Tree()
: // what does this colon signify?
left(0),
right(0),
node(0)
{
}
Sets left, right, and node to 0. It's mostly the same as:
Code:
Tree::Tree()
{
left = 0;
right = 0;
node = 0;
}
but the first method is preferred. There are differences:
* Initializer lists can offer improved performance.
* Initializer lists are the ONLY place you can correctly call a base constructor.
* Initialization happens in the order the variables are defined, NOT the order of the list itself. E.g. in this code:
Code:
class X{
public:
X() : y(0), x(7), z(22){}
private:
int x, y, z;
};
The variables are instantiated beginning with *x*, then y, then z, because that is the order they are declared in the class. The order they are declared in the initializer list is irrelevant (although, for readability, I always make both orders the same).