isocpp / isocpp/CppCoreGuidelines
NL.16: Is initialization order a noteworthy exception to the rule?
Open
@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
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Assessment
This issue has not been assessed yet.