isocpp / isocpp/CppCoreGuidelines

NL.16: Is initialization order a noteworthy exception to the rule?

Open
#540 1 comment 0 reactions 1 assignee View on GitHub

@gdr-at-ms is already working on this.

Since May 15, 2017.

open
Dominant language
CSS
Stars
45.3k
Forks
5.6k
PR merge metrics
No merged PRs in 30d

Description

NL.16 recommends that members be laid out in public, protected, private order.

Like many people, I do this as a matter of habit without giving it any second thought. Sometimes however the initialization order of members requires me to break this rule.

Something like:

class Foo {
private:
  int handle;
public:
  Foo () :
    handle(some_func()),
    width(handle_width(handle)),
    height(handle_height(handle))
  {}
  const int width, height;
};

... where width and height's initializers require handle to be set.

Is this worth stating as an exception?

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.