Constructor initialization list: code from the C++ Primer, chapter 16 -


At the end of chapter 16 of "C ++ primer" I had to face the following code (I removed a group of lines Given):

  class cells_item {public: // default constructor: unbound handle sales_tyme (): h () {} private: handles & lt; Item_base & gt; H; // use-count handle};  

My problem is with Sales_item (): h () {} line

For the sake of completeness, let me handle my handle class templates. Also quote some parts which I think are relevant to my question (I think I do not need to show item_base class):

  template  

I would expect something either:

a) sales_item (): h (0) {} which is a conference writers Has used repeatedly in the first chapters, or

b) handles & lieutenant; Item_base & gt; () If this aim was to invite the default constructor of the handle class

Instead, the book has Sales_item (): h () {} . My gut reaction is that it is a typo, because H () suspiciously looks like a function declaration. On the other hand, I just tried to compile under G ++ and run the example code that uses this class and it is working correctly, any thoughts?

Edit: All good answers, thanks! The relevant quotation of chapter 12 of the same book has been tracked in 30 minutes between me: "When we start a member of class type, then we specify the debate for passing one of that member's types of consultants We are able to use any of that kind of consultants. "And as you all have said, in this case we are passing zero arguments.

What do you have sales_item (): h () {} Data member is a constructor with the start

I would either have something like this:

a) Sales_item (): h (0) {} Which is a conference writer, is used repeatedly in previous chapters, or

This is not necessary because the constellation handles & lt; Item _base & gt; () can be applied without argument (its argument is a default value, so it can be omitted.)

b) handles & lt ; Item _base & gt; () If the intent of the default constructor handle class

This is just a false syntax. This syntax is used for base classes and it is fine, because any class Handles & lt; Item_base & gt; () can be inherited only once. However, there may be many data elements of that type, so to start the right data member, its name is used instead of its type.


This is a very good book that you are learning from BTW. Once you are through it, you will want to look for better input.


Comments