☰
  • 首页
  • 规则分类
  • 项目介绍
search
•••

类成员应按 public、protected、private 的顺序声明

5.1.20 ID_accessSpecifierDisorder
目录 › next › previous

类成员统一按 public、protected、private 的顺序声明,有利于提高可读性。

示例:

class A   // Bad
{
private:
    int baz();

public:
    int foo();

protected:
    int bar();
};

供外部使用的 public 成员应作为重点写在前面,其次是 protected 成员,private 成员应写在最后:

class A   // Good
{
public:
    int foo();

protected:
    int bar();

private:
    int baz();
};

参考

C++ Core Guidelines NL.16
Copyright©2024 360 Security Technology Inc., Licensed under the Apache-2.0 license.