mirror of
https://github.com/isocpp/CppCoreGuidelines.git
synced 2024-03-22 13:30:58 +08:00
parent
0df2c26e9a
commit
edbfc3b8ec
|
@ -20294,10 +20294,6 @@ When declaring a class use the following order
|
||||||
|
|
||||||
Use the `public` before `protected` before `private` order.
|
Use the `public` before `protected` before `private` order.
|
||||||
|
|
||||||
Private types and functions can be placed with private data.
|
|
||||||
|
|
||||||
Avoid multiple blocks of declarations of one access (e.g., `public`) dispersed among blocks of declarations with different access (e.g. `private`).
|
|
||||||
|
|
||||||
##### Example
|
##### Example
|
||||||
|
|
||||||
class X {
|
class X {
|
||||||
|
@ -20309,9 +20305,33 @@ Avoid multiple blocks of declarations of one access (e.g., `public`) dispersed a
|
||||||
// implementation details
|
// implementation details
|
||||||
};
|
};
|
||||||
|
|
||||||
##### Note
|
##### Example
|
||||||
|
|
||||||
The use of macros to declare groups of members often violates any ordering rules.
|
Sometimes, the default order of members conflicts with a desire to separate the public interface from implementation details.
|
||||||
|
In such cases, private types and functions can be placed with private data.
|
||||||
|
|
||||||
|
class X {
|
||||||
|
public:
|
||||||
|
// interface
|
||||||
|
protected:
|
||||||
|
// unchecked function for use by derived class implementations
|
||||||
|
private:
|
||||||
|
// implementation details (types, functions, and data)
|
||||||
|
};
|
||||||
|
|
||||||
|
##### Example, bad
|
||||||
|
|
||||||
|
Avoid multiple blocks of declarations of one access (e.g., `public`) dispersed among blocks of declarations with different access (e.g. `private`).
|
||||||
|
|
||||||
|
class X { // bad
|
||||||
|
public:
|
||||||
|
void f();
|
||||||
|
public:
|
||||||
|
int g();
|
||||||
|
// ...
|
||||||
|
};
|
||||||
|
|
||||||
|
The use of macros to declare groups of members often leads to violation of any ordering rules.
|
||||||
However, macros obscures what is being expressed anyway.
|
However, macros obscures what is being expressed anyway.
|
||||||
|
|
||||||
##### Enforcement
|
##### Enforcement
|
||||||
|
|
Loading…
Reference in New Issue
Block a user