Chapter 6: Constructors

Hi everyone, I’m trying to understand constructors and how I should categorise them in my brain. Does this diagram make any sense at all or is trying to chart constructors like this a futile mission?

I like how you categorize information with diagrams like this. It made me wonder if we should include a diagram for constructors in the next edition of the book.

I think your diagram is fine in as far as it goes, but it is also incomplete. For example, your diagram makes it look like factory constructors can’t be named or can’t have parameters, but they can.

I may have to take this back upon further reflection and testing, but I believe you can have any combination of the following aspects of constructors:

  • Generative or factory
  • With parameters or without (default)
  • Named or unnamed
  • Forwarding or non-forwarding
  • Short-form or long-form
  • Private or public constructor
  • Constant or not constant

Well, I guess the default constructor without parameters wouldn’t have a long vs short form but it could still be constant or private.

Feel free to list other combinations that aren’t possible.

1 Like