Constructors of C++ classes can have initializer lists, which is what you see there. An initializer list is a comma-separated list that specifies the constructor to use for each member variable of the class. This is more efficient than assigning the variable a value inside the constructor's body because the initializer list constructs the object with the right value, while assignment inside the constructor takes place only after the data type's default constructor has run. Therefore: You have 1 constructor call in the initializer list, but you have 1 constructor call and 1 call to operator= for assignments inside the constructor's body.
class SomeData
{
private:
std::string m_id;
public:
SomeData(const std::string &id)
: m_id(id) //This is specifying that m_id be initialized using the copy constructor
{ }
SomeData()
: m_id() //The default constructor. This is the same as not specifying the variable in the initializer list.
{ }
};
class SomeData2
{
private:
std::string m_id;
public:
SomeData2(const std::string &id)
{
m_id = id; //This code executes std::string's operator=, but only after m_id has been constructed. A waste of cycles.
}
};