This is a member initialization list. In the example you gave above, the class member variables int1, int2, and int3 would all be initialized with the value 0.
Basically in an initialization list you do just that: specify initial values for member variables.
Some Notes:
1. Class members are initialized in the order that they're declared in the class declaration. The order in which they're listed in the member initialization list doesn't matter. Thus, you might get burnt by doing something like this:
class CCustomer
{
public:
// One-parameter constructor for when shipping address is the same as billing address
CCustomer( const CString& rsAddress );
CString m_sBillingAddress;
CString m_sShippingAddress;
};
CCustomer::CCustomer( const CString& rsAddress ) :
m_sShippingAddress( rsAddress ),
m_sBillingAddress( m_sShippingAddress )
{
}
The CCustomer constructor will crash because it tries to initialize m_sBillingAddress by copying m_sShippingAddress, but m_sShippingAddress hasn't been constructed yet.
2. In some cases, you must use a member initializer list. For instance, the following code doesn't compile:
class CCustomer
{
public:
// One-parameter constructor for when shipping address is the same as billing address
CCustomer( const CString& rsAddress );
const CString m_sBillingAddress;
const CString m_sShippingAddress;
};
CCustomer::CCustomer( const CString& rsAddress ) :
{
m_sBillingAddress = rsAddress;
m_sShippingAddress = rsAddress;
}
"const" member variables, as shown in this example, must be initialized in the member initialization list. Other times that you need to use a member initialization list are:
A. When the member is of a class type that has no default [that is, parameterless] constructor
B. When the member is a reference.
3. Member initialization lists can improve efficiency. Imagine that the code shown in the last example didn't declare the member variables as const. Thus it would compile. However, the compiler would generate two function calls for each CString: one to the CString default constructor and one to the assignment operator. By using a member initialization list, the compiler generates only a single call to the CString copy constructor.
One last note: to be totally technical, int1, int2, and int3 could be base classes, and not class members. In that case you would be passing the value 0 to three base class constructors. But I don't think that's what was intended by your example.